diff --git a/nfu_wholesaler_exporter/README.rst b/nfu_wholesaler_exporter/README.rst index 50c9cb0..4e40209 100644 --- a/nfu_wholesaler_exporter/README.rst +++ b/nfu_wholesaler_exporter/README.rst @@ -46,6 +46,7 @@ Changelog :0.0.1: Initial module. :1.0.0: Adjust to Grell format specification :1.0.1: Rename to CSV Exporter +:1.1.0: Add rounding for float values and remove zero lines Bug Tracker =========== diff --git a/nfu_wholesaler_exporter/__manifest__.py b/nfu_wholesaler_exporter/__manifest__.py index db3c0b5..979489c 100644 --- a/nfu_wholesaler_exporter/__manifest__.py +++ b/nfu_wholesaler_exporter/__manifest__.py @@ -4,8 +4,8 @@ "author": "BAKEUP", "website": "https://www.bakeup.org", "category": "Sale", - "version": "16.0.1.0.1", - "depends": ["sale_order_batch"], + "version": "16.0.1.1.0", + "depends": ["sale_order_batch", "nfu_sale_order_batch_packaging"], "data": ["views/sale_order_batch_views.xml"], "license": "LGPL-3", } diff --git a/nfu_wholesaler_exporter/models/sale_order_batch.py b/nfu_wholesaler_exporter/models/sale_order_batch.py index 36f243a..80a30fa 100644 --- a/nfu_wholesaler_exporter/models/sale_order_batch.py +++ b/nfu_wholesaler_exporter/models/sale_order_batch.py @@ -1,6 +1,8 @@ import base64 -from odoo import models +from odoo import _, models +from odoo.exceptions import UserError +from odoo.tools import float_is_zero class SaleOrderBatch(models.Model): @@ -11,8 +13,12 @@ class SaleOrderBatch(models.Model): # Prepare CSV content csv_content = "Artnr,Menge\n" for product in self.product_ids.filtered(lambda p: p.product_id.default_code): - wholesaler_qty = int(product.product_uom_qty / product.product_packaging_qty) - csv_content += f"{product.product_id.default_code},{wholesaler_qty}\n" + if not float_is_zero(product.product_uom_qty, precision_rounding=product.product_id.uom_id.rounding): + # We think 10g variance is okay + if not float_is_zero(product.open_packaging_qty, precision_rounding=0.01): + raise UserError(_(f"Packaging is still open for product {product.product_id.name}")) + wholesaler_qty = int(round(product.product_uom_qty / product.product_packaging_qty)) + csv_content += f"{product.product_id.default_code},{wholesaler_qty}\n" # Encode CSV content to base64 csv_base64 = base64.b64encode(csv_content.encode("utf-8")) diff --git a/nfu_wholesaler_exporter/readme/HISTORY.rst b/nfu_wholesaler_exporter/readme/HISTORY.rst index 602a656..38148e9 100644 --- a/nfu_wholesaler_exporter/readme/HISTORY.rst +++ b/nfu_wholesaler_exporter/readme/HISTORY.rst @@ -1,3 +1,4 @@ :0.0.1: Initial module. :1.0.0: Adjust to Grell format specification -:1.0.1: Rename to CSV Exporter \ No newline at end of file +:1.0.1: Rename to CSV Exporter +:1.1.0: Add rounding for float values and remove zero lines \ No newline at end of file diff --git a/nfu_wholesaler_exporter/static/description/index.html b/nfu_wholesaler_exporter/static/description/index.html index cad51df..de6bb6e 100644 --- a/nfu_wholesaler_exporter/static/description/index.html +++ b/nfu_wholesaler_exporter/static/description/index.html @@ -413,6 +413,8 @@ Das ist aktuell der default_code, falls wir den mal prefixen, muss das hier ange 1.0.1:Rename to CSV Exporter +1.1.0:Add rounding for float values and remove zero lines +