[IMP] nfu_wholesaler_exporter: Add rounding for float values and remove zero lines

This commit is contained in:
Niels Göttsch 2024-10-17 06:54:27 +02:00
parent 5745d99c6d
commit eee220613a
5 changed files with 16 additions and 6 deletions

View file

@ -46,6 +46,7 @@ Changelog
:0.0.1: Initial module. :0.0.1: Initial module.
:1.0.0: Adjust to Grell format specification :1.0.0: Adjust to Grell format specification
:1.0.1: Rename to CSV Exporter :1.0.1: Rename to CSV Exporter
:1.1.0: Add rounding for float values and remove zero lines
Bug Tracker Bug Tracker
=========== ===========

View file

@ -4,8 +4,8 @@
"author": "BAKEUP", "author": "BAKEUP",
"website": "https://www.bakeup.org", "website": "https://www.bakeup.org",
"category": "Sale", "category": "Sale",
"version": "16.0.1.0.1", "version": "16.0.1.1.0",
"depends": ["sale_order_batch"], "depends": ["sale_order_batch", "nfu_sale_order_batch_packaging"],
"data": ["views/sale_order_batch_views.xml"], "data": ["views/sale_order_batch_views.xml"],
"license": "LGPL-3", "license": "LGPL-3",
} }

View file

@ -1,6 +1,8 @@
import base64 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): class SaleOrderBatch(models.Model):
@ -11,7 +13,11 @@ class SaleOrderBatch(models.Model):
# Prepare CSV content # Prepare CSV content
csv_content = "Artnr,Menge\n" csv_content = "Artnr,Menge\n"
for product in self.product_ids.filtered(lambda p: p.product_id.default_code): 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) 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" csv_content += f"{product.product_id.default_code},{wholesaler_qty}\n"
# Encode CSV content to base64 # Encode CSV content to base64

View file

@ -1,3 +1,4 @@
:0.0.1: Initial module. :0.0.1: Initial module.
:1.0.0: Adjust to Grell format specification :1.0.0: Adjust to Grell format specification
:1.0.1: Rename to CSV Exporter :1.0.1: Rename to CSV Exporter
:1.1.0: Add rounding for float values and remove zero lines

View file

@ -413,6 +413,8 @@ Das ist aktuell der default_code, falls wir den mal prefixen, muss das hier ange
</tr> </tr>
<tr class="field"><th class="field-name">1.0.1:</th><td class="field-body">Rename to CSV Exporter</td> <tr class="field"><th class="field-name">1.0.1:</th><td class="field-body">Rename to CSV Exporter</td>
</tr> </tr>
<tr class="field"><th class="field-name">1.1.0:</th><td class="field-body">Add rounding for float values and remove zero lines</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>