[IMP] uom: set one unit as a Reference Unit

Before this commit, the user was able to change the UoM type from
"Reference Unit" to "Bigger" or "Smaller" and let an UoM category with
no reference.
So, to force UoM category to have at least one Reference Unit, the user
can't change the reference unit if there is no other unit set as
reference.

task-2581265

Part-of: odoo/odoo#74695
This commit is contained in:
Vishal Thacker
2021-11-26 15:10:24 +00:00
committed by svs-odoo
parent b43ac31f70
commit b1e328d369
+1 -6
View File
@@ -24,12 +24,7 @@ class UoMCategory(models.Model):
else:
reference_count = sum(uom.uom_type == 'reference' for uom in self.uom_ids)
if reference_count == 0 and self._origin.id:
return {
'warning': {
'title': _('Warning!'),
'message': _("UoM category %s should have a reference unit of measure.") % self.name
}
}
raise UserError(_('UoM category %s must have at least one reference unit of measure.', self.name))
if self.reference_uom_id:
new_reference = self.uom_ids.filtered(lambda o: o.uom_type == 'reference' and o._origin.id != self.reference_uom_id.id)
else: