[FIX] registry: ensure that all non-abstract models have a table (#14194)

After modifying the database schema, if some models do not have a table/view,
attempt to recreate it by calling their method `init()`, following inter-model
dependencies.

Fix the model `board.board` by making it an abstract model.

Add the missing model dependencies on report `crm.partner.report.assign` to make
it depend on report `account.invoice.report`.
This commit is contained in:
Raphael Collet
2016-11-10 13:50:04 +01:00
committed by GitHub
parent 5a45ed00fa
commit f825f415f8
3 changed files with 26 additions and 11 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
from odoo import api, models
class Board(models.Model):
class Board(models.AbstractModel):
_name = 'board.board'
_description = "Board"
_auto = False
@@ -23,6 +23,13 @@ class CrmPartnerReportAssign(models.Model):
turnover = fields.Float('Turnover', readonly=True)
date = fields.Date('Invoice Account Date', readonly=True)
_depends = {
'account.invoice.report': ['date', 'partner_id', 'price_total', 'state', 'type'],
'crm.lead': ['partner_assigned_id'],
'res.partner': ['activation', 'country_id', 'date_partnership', 'date_review',
'grade_id', 'parent_id', 'team_id', 'user_id'],
}
@api.model_cr
def init(self):
"""
@@ -50,13 +57,3 @@ class CrmPartnerReportAssign(models.Model):
left join account_invoice_report i
on (i.partner_id=p.id and i.type in ('out_invoice','out_refund') and i.state in ('open','paid'))
)""")
class AccountInvoiceReport(models.Model):
_inherit = 'account.invoice.report'
@api.model_cr
def init(self):
# ensure we re-create the crm_partner_report_assign view whenever
# the underlying account_invoice_report view is changed
super(AccountInvoiceReport, self).init()
self.env['crm.partner.report.assign'].init()
+18
View File
@@ -327,6 +327,24 @@ class Registry(Mapping):
models[0].recompute()
cr.commit()
# make sure all tables are present
missing = [name
for name, model in env.items()
if not model._abstract and not model._table_exist()]
if missing:
_logger.warning("Models have no table: %s.", ", ".join(missing))
# recreate missing tables following model dependencies
deps = {name: model._depends for name, model in env.items()}
for name in topological_sort(deps):
if name in missing:
_logger.info("Recreate table of model %s.", name)
env[name].init()
cr.commit()
# check again, and log errors if tables are still missing
for name, model in env.items():
if not model._abstract and not model._table_exist():
_logger.error("Model %s has no table.", name)
def clear_caches(self):
""" Clear the caches associated to methods decorated with
``tools.ormcache`` or ``tools.ormcache_multi`` for all the models.