[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`.

This commit is contained in:
Denis Ledoux 2015-11-26 13:53:55 +01:00
parent da667b573d
commit 1b8c9aed9f
3 changed files with 6 additions and 12 deletions

View File

@ -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',

View File

@ -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'):
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:

View File

@ -41,7 +41,7 @@
<page string="Fields">
<field context="{'manual':True}" name="field_id">
<field name="field_id">
<tree string="Fields Description">
<field name="name"/>
<field name="field_description"/>
@ -142,7 +142,7 @@
<field name="name">Models</field>
<field name="res_model">ir.model</field>
<field name="view_type">form</field>
<field name="context">{'manual':True}</field>
<field name="context">{}</field>
<field name="view_id" ref="view_model_tree"/>
<menuitem action="action_model_model" id="ir_model_model_menu" parent="next_id_9"/>
@ -237,7 +237,7 @@
<field name="name">Fields</field>
<field name="res_model">ir.model.fields</field>
<field name="view_type">form</field>
<field name="context">{'manual':True}</field>
<field name="context">{}</field>
<field name="view_id" ref="view_model_fields_tree"/>
<menuitem action="action_model_fields" id="ir_model_model_fields" parent="base.next_id_9"/>