[FIX] uom: fix nonempty reference constraint on uom categories
What's the deal with SQL queries? The query in _check_category_reference_uniqueness returns: category_id | uom_count -------------+----------- (0 rows) but if we removed AND U.active = 't', we would have had: category_id | uom_count -------------+----------- 8 | 0 (1 row) As a result, the check on uom_data['uom_count'] == 0 could simply never be true. opw 1959679 closes odoo/odoo#32788 Signed-off-by: Nans Lefebvre (len) <len@odoo.com>
This commit is contained in:
@@ -83,9 +83,8 @@ class UoM(models.Model):
|
||||
self._cr.execute("""
|
||||
SELECT C.id AS category_id, count(U.id) AS uom_count
|
||||
FROM uom_category C
|
||||
LEFT JOIN uom_uom U ON C.id = U.category_id AND uom_type = 'reference'
|
||||
LEFT JOIN uom_uom U ON C.id = U.category_id AND uom_type = 'reference' AND U.active = 't'
|
||||
WHERE C.id IN %s
|
||||
AND U.active = 't'
|
||||
GROUP BY C.id
|
||||
""", (tuple(category_ids),))
|
||||
for uom_data in self._cr.dictfetchall():
|
||||
|
||||
@@ -68,6 +68,16 @@ class TestUom(TransactionCase):
|
||||
'name': 'Custom UoM category',
|
||||
})
|
||||
|
||||
# at first we can not create a non reference in custom category
|
||||
with self.assertRaises(ValidationError):
|
||||
self.env['uom.uom'].create({
|
||||
'name': 'Bigger UoM of my category',
|
||||
'factor_inv': 42,
|
||||
'uom_type': 'bigger',
|
||||
'rounding': 0.5,
|
||||
'category_id': category.id
|
||||
})
|
||||
|
||||
# create the reference
|
||||
self.env['uom.uom'].create({
|
||||
'name': 'Reference UoM of my category',
|
||||
|
||||
Reference in New Issue
Block a user