diff options
| author | Simon Lejeune <sle@openerp.com> | 2019-12-05 13:58:04 +0000 |
|---|---|---|
| committer | Simon Lejeune <sle@openerp.com> | 2019-12-10 09:02:53 +0000 |
| commit | 80b55624c855820d2a49882974676e4d9c89225e (patch) | |
| tree | 9e2d68b26f4088b385ae19e18ccb0da81b95777e /addons/uom | |
| parent | 1492e1a644c1cd952876214a1be701d41dc96337 (diff) | |
[FIX] uom: _check_category_reference_uniqueness
Edit the liters uom (default in its category) and change its category to
unit. You now have two references uom in the unit category. Try to set a
third one and now it fails.
This was because the constraint is implemented with an sql query but
since the new ORM the update in database are delayed. We force a
database update with flush so that the query gant get all the
informations it needs.
closes odoo/odoo#41621
X-original-commit: 68ced7972db64b22a4ff031bba0f78c06a88372d
Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
Diffstat (limited to 'addons/uom')
| -rw-r--r-- | addons/uom/models/uom_uom.py | 1 | ||||
| -rw-r--r-- | addons/uom/tests/test_uom.py | 6 |
2 files changed, 7 insertions, 0 deletions
diff --git a/addons/uom/models/uom_uom.py b/addons/uom/models/uom_uom.py index beee90fbf43..5d18143b4f3 100644 --- a/addons/uom/models/uom_uom.py +++ b/addons/uom/models/uom_uom.py @@ -79,6 +79,7 @@ class UoM(models.Model): not possible to do it in SQL directly. """ category_ids = self.mapped('category_id').ids + self.env['uom.uom'].flush(['category_id', 'uom_type', 'active']) self._cr.execute(""" SELECT C.id AS category_id, count(U.id) AS uom_count FROM uom_category C diff --git a/addons/uom/tests/test_uom.py b/addons/uom/tests/test_uom.py index 1b7dd2b1e1a..935bb6a12cb 100644 --- a/addons/uom/tests/test_uom.py +++ b/addons/uom/tests/test_uom.py @@ -62,6 +62,12 @@ class TestUom(TransactionCase): 'category_id': time_category.id }) + def test_31_reference_uniqueness(self): + """ Check the uniqueness of the reference UoM in a category """ + time_category = self.env['uom.category'].search([('measure_type', '=', 'working_time')], limit=1) + with self.assertRaises(ValidationError): + self.env['uom.uom'].search([('measure_type', '=', 'unit'), ('uom_type', '=', 'reference')]).category_id = time_category + def test_40_custom_uom(self): """ A custom UoM is an UoM in a category without measurement type. It should behave like a normal UoM """ category = self.env['uom.category'].create({ |
