diff --git a/addons/uom/i18n/uom.pot b/addons/uom/i18n/uom.pot index c773635f0ac681252a3d7df12498c4674490f8ab..e5f8c4e7cc5d86f9791786f1dd0c5d8ca2e850ce 100644 --- a/addons/uom/i18n/uom.pot +++ b/addons/uom/i18n/uom.pot @@ -274,6 +274,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 a23a99f50980d5cd630dca629f8176d83473a0a0..7d84ae13d333c8d93bc1ea4a906a4353e5a07c1c 100644 --- a/addons/uom/models/uom_uom.py +++ b/addons/uom/models/uom_uom.py @@ -108,6 +108,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 2c3f7f9d3fd888119194e2bdf4fbc2748b493b1d..55260ae2b4ce777b5db55f70d6bec88c0b6bd1b2 100644 --- a/addons/uom/tests/test_uom.py +++ b/addons/uom/tests/test_uom.py @@ -97,3 +97,12 @@ class TestUom(UomCommon): '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.env.ref('uom.product_uom_categ_unit').id + })