diff --git a/addons/uom/i18n/uom.pot b/addons/uom/i18n/uom.pot index f5834d2cd04ce9a97bd670942569481ee112f831..c77e2a6041b839cfa3d8f0c3e1f7a69f459a0e4c 100644 --- a/addons/uom/i18n/uom.pot +++ b/addons/uom/i18n/uom.pot @@ -279,6 +279,12 @@ msgid "" " belong to the same category." msgstr "" +#. module: uom +#: code:addons/uom/models/uom_uom.py:0 +#, python-format +msgid "The value of ratio could not be Zero" +msgstr "" + #. module: uom #: model:ir.model.fields,field_description:uom.field_uom_uom__uom_type msgid "Type" diff --git a/addons/uom/models/uom_uom.py b/addons/uom/models/uom_uom.py index 3f770fd0850b17d48f08e601058172fbf6ab97e0..85b153384e90de51ca43e84ec5624cd8d0ed6f8b 100644 --- a/addons/uom/models/uom_uom.py +++ b/addons/uom/models/uom_uom.py @@ -113,6 +113,8 @@ class UoM(models.Model): uom.ratio = uom.factor def _set_ratio(self): + if self.ratio == 0: + raise ValidationError(_("The value of ratio could not be Zero")) if self.uom_type == 'reference': self.factor = 1 elif self.uom_type == 'bigger': diff --git a/addons/uom/tests/test_uom.py b/addons/uom/tests/test_uom.py index 9abe66e55ba2b738e3b1dda3e8c67ae94632515f..986d5de09a9e4a1101d244834426453c7299647e 100644 --- a/addons/uom/tests/test_uom.py +++ b/addons/uom/tests/test_uom.py @@ -105,3 +105,12 @@ class TestUom(TransactionCase): 'rounding': 1.0, 'category_id': category.id }) + + def test_50_check_ratio(self): + with self.assertRaises(ValidationError): + self.env['uom.uom'].create({ + 'name': 'Custom UoM', + 'uom_type': 'bigger', + 'ratio': 0, + 'category_id': self.categ_unit_id + })