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_main_flows | |
| 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_main_flows')
| -rw-r--r-- | odoo/addons/test_main_flows/tests/test_flow.py | 33 |
1 files changed, 7 insertions, 26 deletions
diff --git a/odoo/addons/test_main_flows/tests/test_flow.py b/odoo/addons/test_main_flows/tests/test_flow.py index fe86f8187c6..2f359d4cccc 100644 --- a/odoo/addons/test_main_flows/tests/test_flow.py +++ b/odoo/addons/test_main_flows/tests/test_flow.py @@ -36,32 +36,13 @@ class TestUi(odoo.tests.HttpCase): 'user_type_id': self.env.ref('account.data_account_type_liquidity').id, }) - self.env['ir.property'].create([{ - 'name': 'property_account_receivable_id', - 'fields_id': self.env['ir.model.fields'].search([('model', '=', 'res.partner'), ('name', '=', 'property_account_receivable_id')], limit=1).id, - 'value': 'account.account,%s' % (a_recv.id), - 'company_id': self.env.company.id, - }, { - 'name': 'property_account_payable_id', - 'fields_id': self.env['ir.model.fields'].search([('model', '=', 'res.partner'), ('name', '=', 'property_account_payable_id')], limit=1).id, - 'value': 'account.account,%s' % (a_pay.id), - 'company_id': self.env.company.id, - }, { - 'name': 'property_account_position_id', - 'fields_id': self.env['ir.model.fields'].search([('model', '=', 'res.partner'), ('name', '=', 'property_account_position_id')], limit=1).id, - 'value': False, - 'company_id': self.env.company.id, - }, { - 'name': 'property_account_expense_categ_id', - 'fields_id': self.env['ir.model.fields'].search([('model', '=', 'product.category'), ('name', '=', 'property_account_expense_categ_id')], limit=1).id, - 'value': 'account.account,%s' % (a_expense.id), - 'company_id': self.env.company.id, - }, { - 'name': 'property_account_income_categ_id', - 'fields_id': self.env['ir.model.fields'].search([('model', '=', 'product.category'), ('name', '=', 'property_account_income_categ_id')], limit=1).id, - 'value': 'account.account,%s' % (a_sale.id), - 'company_id': self.env.company.id, - }]) + Property = self.env['ir.property'] + Property.set_default('property_account_receivable_id', 'res.partner', a_recv, self.env.company) + Property.set_default('property_account_payable_id', 'res.partner', a_pay, self.env.company) + Property.set_default('property_account_position_id', 'res.partner', False, self.env.company) + Property.set_default('property_account_expense_categ_id', 'product.category', a_expense, self.env.company) + Property.set_default('property_account_income_categ_id', 'product.category', a_sale, self.env.company) + self.expenses_journal = self.env['account.journal'].create({ 'name': 'Vendor Bills - Test', 'code': 'TEXJ', |
