[FIX] ir_model: invalidate cache when adding new fields
When a new ir.model.field is created, add the new field in the fields_by_model (cache of custom fields). This is required as the __init__ method would not retrieve the new field if fields_by_model is already set. Otherwise, the _columns would not contain the new fields and we could not access it without restarting the server (e.g. the installation of a module adds ir.model.fields and use it in the a view.
This commit is contained in:
parent
8fe9f07cac
commit
0ab88f54f9
|
@ -361,6 +361,10 @@ class ir_model_fields(osv.osv):
|
||||||
if self.pool.get(vals['model']):
|
if self.pool.get(vals['model']):
|
||||||
if vals['model'].startswith('x_') and vals['name'] == 'x_name':
|
if vals['model'].startswith('x_') and vals['name'] == 'x_name':
|
||||||
self.pool[vals['model']]._rec_name = 'x_name'
|
self.pool[vals['model']]._rec_name = 'x_name'
|
||||||
|
|
||||||
|
if self.pool.fields_by_model is not None:
|
||||||
|
cr.execute('SELECT * FROM ir_model_fields WHERE id=%s', (res,))
|
||||||
|
self.pool.fields_by_model.setdefault(vals['model'], []).append(cr.dictfetchone())
|
||||||
self.pool.get(vals['model']).__init__(self.pool, cr)
|
self.pool.get(vals['model']).__init__(self.pool, cr)
|
||||||
#Added context to _auto_init for special treatment to custom field for select_level
|
#Added context to _auto_init for special treatment to custom field for select_level
|
||||||
ctx = dict(context,
|
ctx = dict(context,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import test_base
|
import test_base
|
||||||
import test_expression
|
import test_expression
|
||||||
import test_ir_attachment
|
import test_ir_attachment
|
||||||
|
import test_ir_model
|
||||||
import test_ir_values
|
import test_ir_values
|
||||||
import test_menu
|
import test_menu
|
||||||
import test_search
|
import test_search
|
||||||
|
@ -10,6 +11,7 @@ checks = [
|
||||||
test_base,
|
test_base,
|
||||||
test_expression,
|
test_expression,
|
||||||
test_ir_attachment,
|
test_ir_attachment,
|
||||||
|
test_ir_model,
|
||||||
test_ir_values,
|
test_ir_values,
|
||||||
test_menu,
|
test_menu,
|
||||||
test_search,
|
test_search,
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
import unittest2
|
||||||
|
|
||||||
|
import openerp.tests.common as common
|
||||||
|
|
||||||
|
class test_ir_model(common.TransactionCase):
|
||||||
|
|
||||||
|
def test_00(self):
|
||||||
|
# Create some custom model and fields
|
||||||
|
cr, uid, context = self.cr, self.uid, {}
|
||||||
|
|
||||||
|
ir_model = self.registry('ir.model')
|
||||||
|
ir_model_fields = self.registry('ir.model.fields')
|
||||||
|
ir_model_access = self.registry('ir.model.access')
|
||||||
|
candy_model_id = ir_model.create(cr, uid, {
|
||||||
|
'name': 'Candies',
|
||||||
|
'model': 'x_candy',
|
||||||
|
'info': 'List of candies',
|
||||||
|
'state': 'manual',
|
||||||
|
}, context=context)
|
||||||
|
# security rule to avoid warning
|
||||||
|
ir_model_access.create(cr, uid, {
|
||||||
|
'name': 'Candies are for everybody',
|
||||||
|
'model_id': candy_model_id,
|
||||||
|
'perm_read': True,
|
||||||
|
'perm_write': True,
|
||||||
|
'perm_create': True,
|
||||||
|
'perm_unlink': True,
|
||||||
|
})
|
||||||
|
|
||||||
|
assert self.registry('x_candy'), "Custom model not present in registry"
|
||||||
|
|
||||||
|
ir_model_fields.create(cr, uid, {
|
||||||
|
'name': 'x_name',
|
||||||
|
'field_description': 'Name',
|
||||||
|
'model_id': candy_model_id,
|
||||||
|
'state': 'manual',
|
||||||
|
'ttype': 'char',
|
||||||
|
}, context=context)
|
||||||
|
|
||||||
|
assert 'x_name' in self.registry('x_candy')._all_columns, "Custom field not present in registry"
|
||||||
|
assert self.registry('x_candy')._rec_name == 'x_name', "The _rec_name on custom model was not updated"
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest2.main()
|
Loading…
Reference in New Issue