[FIX] Delivery: Endless decimal display on list price

When creating a new delivery method with a provider based on rules, if the base list_base_price was equal to x.8, that ended to a float with endless decimal. (eg: 2.8000000000003)
This fix modify the display to show a rounded value.

closes odoo/odoo#54177

Task-id: 2272472
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
This commit is contained in:
Robin Heinz
2020-07-22 12:47:37 +00:00
parent 5adb0463ea
commit c6d5948c75
+4 -4
View File
@@ -14,13 +14,13 @@ class PriceRule(models.Model):
@api.depends('variable', 'operator', 'max_value', 'list_base_price', 'list_price', 'variable_factor')
def _compute_name(self):
for rule in self:
name = 'if %s %s %s then' % (rule.variable, rule.operator, rule.max_value)
name = 'if %s %s %.02f then' % (rule.variable, rule.operator, rule.max_value)
if rule.list_base_price and not rule.list_price:
name = '%s fixed price %s' % (name, rule.list_base_price)
name = '%s fixed price %.02f' % (name, rule.list_base_price)
elif rule.list_price and not rule.list_base_price:
name = '%s %s times %s' % (name, rule.list_price, rule.variable_factor)
name = '%s %.02f times %s' % (name, rule.list_price, rule.variable_factor)
else:
name = '%s fixed price %s plus %s times %s' % (name, rule.list_base_price, rule.list_price, rule.variable_factor)
name = '%s fixed price %.02f plus %.02f times %s' % (name, rule.list_base_price, rule.list_price, rule.variable_factor)
rule.name = name
name = fields.Char(compute='_compute_name')