From 847d34c88909cfc76854ca9014d7f445ed1a72c8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20G=C3=B6ttsch?=
Date: Mon, 7 Oct 2024 21:37:25 +0200
Subject: [PATCH] [IMP] nfu_ecommerce: Add open packaging filter to webshop
---
nfu_ecommerce/README.rst | 2 +-
nfu_ecommerce/i18n/de.po | 120 ++++++++++++++++++++
nfu_ecommerce/models/sale_order_line.py | 29 ++++-
nfu_ecommerce/readme/HISTORY.rst | 2 +-
nfu_ecommerce/static/description/index.html | 2 +-
nfu_ecommerce/views/templates.xml | 8 +-
6 files changed, 152 insertions(+), 11 deletions(-)
create mode 100644 nfu_ecommerce/i18n/de.po
diff --git a/nfu_ecommerce/README.rst b/nfu_ecommerce/README.rst
index 5fef683..1c8b81e 100644
--- a/nfu_ecommerce/README.rst
+++ b/nfu_ecommerce/README.rst
@@ -37,7 +37,7 @@ Changelog
:0.0.1: Initial module.
:1.0.0: Live
-:1.1.0: Add Open Packagings Filter
+:1.1.0: Add Open Packagings Filter and fix rounding issue
Bug Tracker
===========
diff --git a/nfu_ecommerce/i18n/de.po b/nfu_ecommerce/i18n/de.po
new file mode 100644
index 0000000..d53d1a0
--- /dev/null
+++ b/nfu_ecommerce/i18n/de.po
@@ -0,0 +1,120 @@
+# Translation of Odoo Server.
+# This file contains the translation of the following modules:
+# * nfu_ecommerce
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: Odoo Server 16.0\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2024-10-04 19:54+0000\n"
+"PO-Revision-Date: 2024-10-04 19:54+0000\n"
+"Last-Translator: \n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Plural-Forms: \n"
+
+#. module: nfu_ecommerce
+#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.cart_lines_packaging
+msgid "Max Qty"
+msgstr "Max Menge"
+
+#. module: nfu_ecommerce
+#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.cart_lines_packaging
+msgid "Add one"
+msgstr "Einen hinzufügen"
+
+#. module: nfu_ecommerce
+#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.o_wsale_offcanvas
+#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.products_open_packaging
+msgid "All Products"
+msgstr "Alle Produkte"
+
+#. module: nfu_ecommerce
+#: model:ir.model.fields,field_description:nfu_ecommerce.field_sale_order__balance
+msgid "Balance"
+msgstr "Guthaben"
+
+#. module: nfu_ecommerce
+#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.total
+msgid "Balance:"
+msgstr "Aktuelles Guthaben:"
+
+#. module: nfu_ecommerce
+#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.cart_lines_packaging
+#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.cart_summary_packaging
+msgid "Max Ordered Quantity:"
+msgstr "Max Menge"
+
+#. module: nfu_ecommerce
+#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.cart_summary_packaging
+msgid "Max Qty"
+msgstr "Max Menge:"
+
+#. module: nfu_ecommerce
+#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.total
+msgid "New balance:"
+msgstr "Neues Guthaben:"
+
+#. module: nfu_ecommerce
+#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.cart_lines_packaging
+msgid "No open package available"
+msgstr "Keine offenen Gebinde"
+
+#. module: nfu_ecommerce
+#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.cart_lines_packaging
+#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.cart_summary_packaging
+msgid "Open Package:"
+msgstr "Offenes Gebinde:"
+
+#. module: nfu_ecommerce
+#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.o_wsale_offcanvas
+#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.products_open_packaging
+msgid "Open Packagings"
+msgstr "Offene Gebinde"
+
+#. module: nfu_ecommerce
+#: model:ir.model.fields,field_description:nfu_ecommerce.field_sale_order_line__open_qty
+msgid "Open Qty"
+msgstr "Offene Menge"
+
+#. module: nfu_ecommerce
+#: model:ir.model,name:nfu_ecommerce.model_product_template
+msgid "Product"
+msgstr "Produkt"
+
+#. module: nfu_ecommerce
+#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.product_template_tree_view
+msgid "Publish on Website"
+msgstr "Veröffentlichen"
+
+#. module: nfu_ecommerce
+#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.cart_lines_packaging
+msgid "Remove one"
+msgstr "Eins entfernen"
+
+#. module: nfu_ecommerce
+#: model:ir.model,name:nfu_ecommerce.model_sale_order
+msgid "Sales Order"
+msgstr "Verkaufsauftrag"
+
+#. module: nfu_ecommerce
+#: model:ir.model,name:nfu_ecommerce.model_sale_order_line
+msgid "Sales Order Line"
+msgstr "Verkaufsauftragszeile"
+
+#. module: nfu_ecommerce
+#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.product_template_tree_view
+msgid "Unpublish on Website"
+msgstr "Von Website entfernen"
+
+#. module: nfu_ecommerce
+#: model:ir.model.fields,field_description:nfu_ecommerce.field_sale_order__updated_balance
+msgid "Updated Balance"
+msgstr "Zukünftiges Guthaben"
+
+#. module: nfu_ecommerce
+#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.cart_lines_packaging
+msgid "Warning"
+msgstr "Warnung"
diff --git a/nfu_ecommerce/models/sale_order_line.py b/nfu_ecommerce/models/sale_order_line.py
index 4f952a8..a3225fa 100644
--- a/nfu_ecommerce/models/sale_order_line.py
+++ b/nfu_ecommerce/models/sale_order_line.py
@@ -1,11 +1,28 @@
-from odoo import models
+from odoo import fields, models
+from odoo.tools import float_is_zero, float_repr, float_round
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
- def compute_open_packages(self):
- self.ensure_one()
- qty_of_last_pack = self.batch_uom_qty % self.product_packaging_id.qty
- open_qty = self.product_packaging_id.qty - qty_of_last_pack
- return open_qty
+ open_qty = fields.Float(compute="_compute_open_qty")
+
+ def _compute_open_qty(self):
+ for line in self:
+ if line.product_packaging_id:
+ precision_rounding = line.product_id.uom_id.rounding
+ precision_digits = len(str(precision_rounding).split(".")[1])
+ qty_of_last_pack = float_round(
+ line.batch_uom_qty % line.product_packaging_id.qty, precision_rounding=precision_rounding
+ )
+ if not float_is_zero(qty_of_last_pack, precision_rounding=precision_rounding):
+ open_qty = float_round(
+ line.product_packaging_id.qty - qty_of_last_pack, precision_rounding=precision_rounding
+ )
+ # somehow float_rounding() does not capture all cases ex. float_rounding(2-1.1)
+ # this is a samll workaround
+ line.open_qty = float(float_repr(open_qty, precision_digits))
+ else:
+ line.open_qty = 0.0
+ else:
+ line.open_qty = 0.0
diff --git a/nfu_ecommerce/readme/HISTORY.rst b/nfu_ecommerce/readme/HISTORY.rst
index f8cb7c8..5e4a8d0 100644
--- a/nfu_ecommerce/readme/HISTORY.rst
+++ b/nfu_ecommerce/readme/HISTORY.rst
@@ -1,3 +1,3 @@
:0.0.1: Initial module.
:1.0.0: Live
-:1.1.0: Add Open Packagings Filter
\ No newline at end of file
+:1.1.0: Add Open Packagings Filter and fix rounding issue
\ No newline at end of file
diff --git a/nfu_ecommerce/static/description/index.html b/nfu_ecommerce/static/description/index.html
index e1e683a..2f4c5c6 100644
--- a/nfu_ecommerce/static/description/index.html
+++ b/nfu_ecommerce/static/description/index.html
@@ -397,7 +397,7 @@ and after the current order.
| 1.0.0: | Live |
-| 1.1.0: | Add Open Packagings Filter |
+
|---|
| 1.1.0: | Add Open Packagings Filter and fix rounding issue |
diff --git a/nfu_ecommerce/views/templates.xml b/nfu_ecommerce/views/templates.xml
index 99ccc7e..49342c2 100644
--- a/nfu_ecommerce/views/templates.xml
+++ b/nfu_ecommerce/views/templates.xml
@@ -28,8 +28,12 @@
- Open Package: /
-
+ Open Package: /
+
+ No open package available
+
Max Ordered Quantity: