[FIX] website_sale_stock: float precision issue

Steps to reproduce the bug:
- Create a product with 123.1 units on hand
- Click the eCommerce tab
- In Availability, choose "Show inventory on website and prevent sales if not enough stock"
- Save
- Go to Website

Bug:
123.10000000000001 is displayed instead of 123.1

opw:2348216

closes odoo/odoo#59020

X-original-commit: 27ab9dcfbb0c8b0400494eda37eea0fc28940524
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
nie
2020-10-02 15:35:21 +00:00
parent 097de9be62
commit e27dc8a1f7
2 changed files with 5 additions and 3 deletions
@@ -27,8 +27,10 @@ class ProductTemplate(models.Model):
if combination_info['product_id']:
product = self.env['product.product'].sudo().browse(combination_info['product_id'])
website = self.env['website'].get_current_website()
virtual_available = product.with_context(warehouse=website.warehouse_id.id).virtual_available
combination_info.update({
'virtual_available': product.with_context(warehouse=website.warehouse_id.id).virtual_available,
'virtual_available': virtual_available,
'virtual_available_formatted': self.env['ir.qweb.field.float'].value_to_html(virtual_available, {'decimal_precision': 'Product Unit of Measure'}),
'product_type': product.type,
'inventory_availability': product.inventory_availability,
'available_threshold': product.available_threshold,
@@ -6,12 +6,12 @@
<t t-if="product_type == 'product' and _.contains(['always', 'threshold'], inventory_availability)">
<t t-if="virtual_available gt 0">
<div t-if="inventory_availability == 'always'" t-attf-class="availability_message_#{product_template} text-success mt16">
<t t-esc="virtual_available" /> <t t-esc="uom_name" /> available
<t t-esc="virtual_available_formatted" /> <t t-esc="uom_name" /> available
</div>
<t t-if="inventory_availability == 'threshold'">
<div t-if="virtual_available lte available_threshold" t-attf-class="availability_message_#{product_template} text-warning mt16">
<i class="fa fa-exclamation-triangle" title="Warning" role="img" aria-label="Warning"/>
<t t-esc="virtual_available" /> <t t-esc="uom_name" /> available
<t t-esc="virtual_available_formatted" /> <t t-esc="uom_name" /> available
</div>
<div t-if="virtual_available gt available_threshold" t-attf-class="availability_message_#{product_template} text-success mt16">In stock</div>
</t>