diff options
| author | Pierre Masereel <pim@odoo.com> | 2019-11-15 15:38:48 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2019-11-22 12:34:43 +0000 |
| commit | e85faf398659a5beb0b1570a06af64dcf78dc1c8 (patch) | |
| tree | 2726de4e47cb5f61bfd748416f85f3fadfb6bf7d /odoo/addons/test_new_api/tests/test_new_fields.py | |
| parent | 8821f0e9176e3b976828f088ce5b7f5c6517b0c7 (diff) | |
[IMP] base: add unique constraint on ir.property
There is no unique constraint on the properties to avoid having two
properties for the same field, company and res_id.
Having two properties for the same field, company and res_id, leads to
inconsistencies through the code, as reading a company-dependent field
nondeterministically returns one of the available property value.
So now, before creating a property, we have to check that there is not
already a value for the field, company and res_id and write or create
depending on if it is already exists.
The properties of specific records already satisfy the constraint thanks
to the implementation of company-dependent fields that use the method
`set_multi`. We added a method `set_default` to set generic properties,
and its implementation does the right thing. It also simplifies the
code to set such properties, by the way.
closes odoo/odoo#40473
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Co-authored-by: Raphael Collet <rco@odoo.com>
Diffstat (limited to 'odoo/addons/test_new_api/tests/test_new_fields.py')
| -rw-r--r-- | odoo/addons/test_new_api/tests/test_new_fields.py | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/odoo/addons/test_new_api/tests/test_new_fields.py b/odoo/addons/test_new_api/tests/test_new_fields.py index b68ae8220fb..5600affc125 100644 --- a/odoo/addons/test_new_api/tests/test_new_fields.py +++ b/odoo/addons/test_new_api/tests/test_new_fields.py @@ -951,12 +951,9 @@ class TestFields(TransactionCaseWithUserDemo): tag2 = self.env['test_new_api.multi.tag'].create({'name': 'Quuz'}) # create default values for the company-dependent fields - field_foo = self.env['ir.model.fields']._get('test_new_api.company', 'foo') - self.env['ir.property'].create({'name': 'foo', 'fields_id': field_foo.id, - 'value': 'default', 'type': 'char'}) - field_tag_id = self.env['ir.model.fields']._get('test_new_api.company', 'tag_id') - self.env['ir.property'].create({'name': 'foo', 'fields_id': field_tag_id.id, - 'value': tag0, 'type': 'many2one'}) + self.env['ir.property'].set_default('foo', 'test_new_api.company', 'default') + self.env['ir.property'].set_default('foo', 'test_new_api.company', 'default1', company1) + self.env['ir.property'].set_default('tag_id', 'test_new_api.company', tag0) # assumption: users don't have access to 'ir.property' accesses = self.env['ir.model.access'].search([('model_id.model', '=', 'ir.property')]) @@ -970,7 +967,7 @@ class TestFields(TransactionCaseWithUserDemo): 'tag_id': tag1.id, }) self.assertEqual(record.with_user(user0).foo, 'main') - self.assertEqual(record.with_user(user1).foo, 'default') + self.assertEqual(record.with_user(user1).foo, 'default1') self.assertEqual(record.with_user(user2).foo, 'default') self.assertEqual(str(record.with_user(user0).date), '1932-11-09') self.assertEqual(record.with_user(user1).date, False) |
