From 1b8c9aed9f516df1c7a51db41e083df2e36b4bf5 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Thu, 26 Nov 2015 13:53:55 +0100 Subject: [PATCH] [FIX] models: custom fields seen as base fields This was possible to create custom fields `x_*` but seen as base fields. For instance, - Go to Settings > Technical > Database Structure > Fields - Select a field (any) - Click on the model link, to be redirected to the model form - Edit & add a custom field from there. - Save - Notice that the field you just added is saved as a base field. We solve this issue by assuming that all created fields and models are customs, except the ones created by the ORM, by the database initialization, the fields coming from the modules in python. We therefore remove the mechanism on which a field was set as custom according to the fact `manual` was set to True within the context: This is now the case by default. No change was required for the base fields: The `state` `base` was already forced for those fields, that are created using direct SQL requests `INSERT INTO`. opw-657312 --- addons/web_view_editor/static/src/js/view_editor.js | 2 +- openerp/addons/base/ir/ir_model.py | 10 ++-------- openerp/addons/base/ir/ir_model_view.xml | 6 +++--- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/addons/web_view_editor/static/src/js/view_editor.js b/addons/web_view_editor/static/src/js/view_editor.js index 96cdcc6f5b7..fdedb82f7b6 100644 --- a/addons/web_view_editor/static/src/js/view_editor.js +++ b/addons/web_view_editor/static/src/js/view_editor.js @@ -1007,7 +1007,7 @@ instance.web_view_editor.ViewEditor = instance.web.Widget.extend({ render_new_field :function( result ) { var self = this; var action = { - context: {'default_model_id': result.id, 'manual': true, 'module' : result.model}, + context: {'default_model_id': result.id, 'module' : result.model}, res_model: "ir.model.fields", views: [[false, 'form']], type: 'ir.actions.act_window', diff --git a/openerp/addons/base/ir/ir_model.py b/openerp/addons/base/ir/ir_model.py index da73a3ab52b..ab21f4b8d50 100644 --- a/openerp/addons/base/ir/ir_model.py +++ b/openerp/addons/base/ir/ir_model.py @@ -129,7 +129,7 @@ class ir_model(osv.osv): _defaults = { 'model': 'x_', - 'state': lambda self,cr,uid,ctx=None: (ctx and ctx.get('manual',False)) and 'manual' or 'base', + 'state': 'manual', } def _check_model_name(self, cr, uid, ids, context=None): @@ -207,8 +207,6 @@ class ir_model(osv.osv): def create(self, cr, user, vals, context=None): if context is None: context = {} - if context and context.get('manual'): - vals['state']='manual' res = super(ir_model,self).create(cr, user, vals, context) if vals.get('state','base')=='manual': # add model in registry @@ -283,7 +281,7 @@ class ir_model_fields(osv.osv): 'selection': "", 'domain': "[]", 'name': 'x_', - 'state': lambda self,cr,uid,ctx=None: (ctx and ctx.get('manual',False)) and 'manual' or 'base', + 'state': 'manual', 'on_delete': 'set null', 'select_level': '0', 'field_description': '', @@ -369,8 +367,6 @@ class ir_model_fields(osv.osv): vals['model'] = model_data.model if context is None: context = {} - if context and context.get('manual',False): - vals['state'] = 'manual' if vals.get('ttype', False) == 'selection': if not vals.get('selection',False): raise except_orm(_('Error'), _('For selection fields, the Selection Options must be given!')) @@ -409,8 +405,6 @@ class ir_model_fields(osv.osv): def write(self, cr, user, ids, vals, context=None): if context is None: context = {} - if context and context.get('manual',False): - vals['state'] = 'manual' #For the moment renaming a sparse field or changing the storing system is not allowed. This may be done later if 'serialization_field_id' in vals or 'name' in vals: diff --git a/openerp/addons/base/ir/ir_model_view.xml b/openerp/addons/base/ir/ir_model_view.xml index bdd5868ce03..5a2547f8e43 100644 --- a/openerp/addons/base/ir/ir_model_view.xml +++ b/openerp/addons/base/ir/ir_model_view.xml @@ -41,7 +41,7 @@ - + @@ -142,7 +142,7 @@ Models ir.model form - {'manual':True} + {} @@ -237,7 +237,7 @@ Fields ir.model.fields form - {'manual':True} + {}