[FIX] uom: prevent set value of ratio as zero in uom
ZeroDivsionError: float division to Zero is generated because for assigning value to 'factor' of uom in method '_set_ratio', it tries to divide value by Zero for uom_type 'Bigger'. Steps to reproduce: 1) Install 'Inventory' module. 2) Click on 'Configuration' > 'Settings'. 3) Activate 'Units of Measure' > click on 'Units of Measure' button under it. 4) Click on 'Create' button to create new uom category. 5) Give any name > in 'Units of Measure' page, click on 'Add a line'. 6) Enter name and select type as 'Reference unit of measure for this category'. 7) Now, add another line and select type as 'Bigger than the the Reference unit of measure' and set the 'ratio' value to Zero, Error will be generated. By applying this,it will check for the value of 'ratio' to prevent division by 0 sentry - 4174584503 closes odoo/odoo#122680 X-original-commit: b79e5afeba7f9517e0325a7a4f9b2373bf5317ed Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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':
|
||||
|
||||
@@ -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
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user