[FIX] Solves the upgrading problem
parent
e7845bd2df
commit
59e90e9868
|
@ -114,6 +114,7 @@ Known issues / Roadmap
|
||||||
======================
|
======================
|
||||||
|
|
||||||
* Add 'interval', after type (row/col/measure) field for date(time) fields.
|
* Add 'interval', after type (row/col/measure) field for date(time) fields.
|
||||||
|
* Possibly avoid the monkey patches
|
||||||
|
|
||||||
Note
|
Note
|
||||||
====
|
====
|
||||||
|
|
|
@ -8,26 +8,35 @@ from psycopg2 import ProgrammingError
|
||||||
|
|
||||||
from odoo import _, api, fields, models, SUPERUSER_ID
|
from odoo import _, api, fields, models, SUPERUSER_ID
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
|
from odoo.tools import pycompat, sql
|
||||||
|
from odoo.addons.base.ir.ir_model import IrModel
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class BaseModel(models.AbstractModel):
|
@api.model
|
||||||
_inherit = 'base'
|
def _instanciate(self, model_data):
|
||||||
|
""" Return a class for the custom model given by
|
||||||
|
parameters ``model_data``. """
|
||||||
|
# This monkey patch is meant to avoid create/search tables for those
|
||||||
|
# materialized views. Doing "super" doesn't work.
|
||||||
|
class CustomModel(models.Model):
|
||||||
|
_name = pycompat.to_native(model_data['model'])
|
||||||
|
_description = model_data['name']
|
||||||
|
_module = False
|
||||||
|
_custom = True
|
||||||
|
_transient = bool(model_data['transient'])
|
||||||
|
__doc__ = model_data['info']
|
||||||
|
|
||||||
@api.model_cr_context
|
# START OF patch
|
||||||
def _auto_init(self):
|
if model_data['model'].startswith(BiSQLView._model_prefix):
|
||||||
if self._name.startswith(BiSQLView._model_prefix):
|
CustomModel._auto = False
|
||||||
if 'update_custom_fields' not in self._context:
|
CustomModel._abstract = True
|
||||||
return True
|
# END of patch
|
||||||
self._auto = False
|
return CustomModel
|
||||||
return super(BaseModel, self)._auto_init()
|
|
||||||
|
|
||||||
@api.model_cr_context
|
|
||||||
def _auto_end(self):
|
IrModel._instanciate = _instanciate
|
||||||
if self._name.startswith(BiSQLView._model_prefix):
|
|
||||||
self._foreign_keys = set()
|
|
||||||
return super(BaseModel, self)._auto_end()
|
|
||||||
|
|
||||||
|
|
||||||
class BiSQLView(models.Model):
|
class BiSQLView(models.Model):
|
||||||
|
@ -212,7 +221,9 @@ class BiSQLView(models.Model):
|
||||||
@api.multi
|
@api.multi
|
||||||
def unlink(self):
|
def unlink(self):
|
||||||
if any(view.state not in ('draft', 'sql_valid') for view in self):
|
if any(view.state not in ('draft', 'sql_valid') for view in self):
|
||||||
raise UserError(_("You can only unlink draft views"))
|
raise UserError(
|
||||||
|
_("You can only unlink draft views."
|
||||||
|
"If you want to delete them, first set them to draft."))
|
||||||
return super(BiSQLView, self).unlink()
|
return super(BiSQLView, self).unlink()
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
|
@ -506,6 +517,7 @@ class BiSQLView(models.Model):
|
||||||
sql_view.rule_id = self.env['ir.rule'].create(
|
sql_view.rule_id = self.env['ir.rule'].create(
|
||||||
self._prepare_rule()).id
|
self._prepare_rule()).id
|
||||||
# Drop table, created by the ORM
|
# Drop table, created by the ORM
|
||||||
|
if sql.table_exists(self._cr, sql_view.view_name):
|
||||||
req = "DROP TABLE %s" % sql_view.view_name
|
req = "DROP TABLE %s" % sql_view.view_name
|
||||||
self._log_execute(req)
|
self._log_execute(req)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue