Browse Source

Restored code for robustness

pull/106/head
Andrea 8 years ago
parent
commit
961520679c
  1. 9
      bi_view_editor/models/bve_view.py
  2. 24
      bi_view_editor/models/ir_model.py

9
bi_view_editor/models/bve_view.py

@ -293,9 +293,8 @@ class BveView(models.Model):
join_nodes = get_join_nodes(info)
table_name = self.model_name.replace('.', '_')
tools.drop_view_if_exists(self.env.cr, table_name)
# this line is only for robustness in case something goes wrong
# robustness in case something went wrong
self._cr.execute('DROP TABLE IF EXISTS "%s"' % table_name)
basic_fields = [
@ -344,6 +343,9 @@ class BveView(models.Model):
vals.update({'selection': selection_domain})
return vals
# clean dirty view (in case something went wrong)
self.action_reset()
# create sql view
self._create_sql_view()
@ -358,7 +360,8 @@ class BveView(models.Model):
for field in data
if 'join_node' not in field]
}
model = self.env['ir.model'].sudo().create(model_vals)
Model = self.env['ir.model'].sudo().with_context(bve=True)
model = Model.create(model_vals)
# give access rights
self._build_access_rules(model)

24
bi_view_editor/models/ir_model.py

@ -3,6 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, models
from odoo.modules.registry import RegistryManager
NO_BI_MODELS = [
'temp.range',
@ -269,3 +270,26 @@ class IrModel(models.Model):
reverse=True
)
return sorted_fields
@api.model
def create(self, vals):
if self._context and self._context.get('bve'):
vals['state'] = 'base'
res = super(IrModel, self).create(vals)
# this sql update is necessary since a write method here would
# be not working (an orm constraint is restricting the modification
# of the state field while updating ir.model)
q = ("""UPDATE ir_model SET state = 'manual'
WHERE id = """ + str(res.id))
self.env.cr.execute(q)
# # update registry
if self._context.get('bve'):
# setup models; this reloads custom models in registry
self.pool.setup_models(self._cr, partial=(not self.pool.ready))
# signal that registry has changed
RegistryManager.signal_registry_change(self.env.cr.dbname)
return res
Loading…
Cancel
Save