From 978011520ca34770568fd5886b2f6615cc047636 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20G=C3=B6ttsch?=
Date: Fri, 4 Oct 2024 17:42:38 +0200
Subject: [PATCH 1/5] [IMP] Add Open Packagings Filter to Webshop
---
nfu_ecommerce/README.rst | 1 +
nfu_ecommerce/__manifest__.py | 2 +-
nfu_ecommerce/controllers/main.py | 41 +++++++++++++++++++
nfu_ecommerce/models/product_template.py | 8 ++++
nfu_ecommerce/readme/HISTORY.rst | 3 +-
nfu_ecommerce/static/description/index.html | 2 +
nfu_ecommerce/views/templates.xml | 19 +++++++++
.../models/sale_order_batch_product.py | 2 +-
8 files changed, 75 insertions(+), 3 deletions(-)
diff --git a/nfu_ecommerce/README.rst b/nfu_ecommerce/README.rst
index 68cbf26..5fef683 100644
--- a/nfu_ecommerce/README.rst
+++ b/nfu_ecommerce/README.rst
@@ -37,6 +37,7 @@ Changelog
:0.0.1: Initial module.
:1.0.0: Live
+:1.1.0: Add Open Packagings Filter
Bug Tracker
===========
diff --git a/nfu_ecommerce/__manifest__.py b/nfu_ecommerce/__manifest__.py
index 12d756c..72f20fe 100644
--- a/nfu_ecommerce/__manifest__.py
+++ b/nfu_ecommerce/__manifest__.py
@@ -4,7 +4,7 @@
"author": "BAKEUP",
"website": "https://www.bakeup.org",
"category": "website",
- "version": "16.0.1.0.0",
+ "version": "16.0.1.1.0",
"depends": ["website_sale", "nfu_sale_order_batch_packaging", "website_decimal_quantity"],
"data": ["views/product_template_views.xml", "views/templates.xml"],
"assets": {"web.assets_frontend": ["nfu_ecommerce/static/src/js/website_sale.js"]},
diff --git a/nfu_ecommerce/controllers/main.py b/nfu_ecommerce/controllers/main.py
index 6f80ec1..52dc815 100644
--- a/nfu_ecommerce/controllers/main.py
+++ b/nfu_ecommerce/controllers/main.py
@@ -1,4 +1,5 @@
from odoo import fields, http
+from odoo.http import request
from odoo.addons.website_sale.controllers.main import WebsiteSale
@@ -10,3 +11,43 @@ class WebsiteSaleMinMax(WebsiteSale):
product_uom_ordered_qty = fields.Float(ordered_qty)
product_uom_max_qty = fields.Float(max_qty)
return super().cart_update(*args, ordered_qty=product_uom_ordered_qty, max_qty=product_uom_max_qty, **kw)
+
+
+class WebsiteSale(WebsiteSale):
+ def _get_search_options(
+ self, category=None, attrib_values=None, pricelist=None, min_price=0.0, max_price=0.0, conversion_rate=1, **post
+ ):
+ res = super()._get_search_options(
+ category=category,
+ attrib_values=attrib_values,
+ pricelist=pricelist,
+ min_price=min_price,
+ max_price=max_price,
+ conversion_rate=conversion_rate,
+ **post
+ )
+ res["open_product_ids"] = post.get("open_product_ids")
+ return res
+
+ @http.route(
+ [
+ "/shop",
+ "/shop/page/",
+ '/shop/category/',
+ '/shop/category//page/',
+ ],
+ type="http",
+ auth="public",
+ website=True,
+ )
+ def shop(self, page=0, category=None, search="", min_price=0.0, max_price=0.0, ppg=False, **post):
+ if post.get("open_packagings"):
+ batch = request.website.sale_get_order(force_create=True).batch_id
+ open_product_ids = (
+ batch.product_ids.filtered(lambda p: p.open_packaging_qty > 0).mapped("product_template_id").ids
+ )
+ post["open_product_ids"] = open_product_ids
+ else:
+ post["open_product_ids"] = []
+ res = super().shop(page=0, category=None, search="", min_price=0.0, max_price=0.0, ppg=False, **post)
+ return res
diff --git a/nfu_ecommerce/models/product_template.py b/nfu_ecommerce/models/product_template.py
index b785776..ab096e6 100644
--- a/nfu_ecommerce/models/product_template.py
+++ b/nfu_ecommerce/models/product_template.py
@@ -11,3 +11,11 @@ class ProductTemplate(models.Model):
def action_unpublish_on_website(self):
for product in self:
product.is_published = False
+
+ def _search_get_detail(self, website, order, options):
+ search_details = super()._search_get_detail(website, order, options)
+ open_product_ids = options.get("open_product_ids")
+ domain = search_details["base_domain"]
+ if len(open_product_ids):
+ domain.append([("id", "in", tuple(open_product_ids))])
+ return search_details
diff --git a/nfu_ecommerce/readme/HISTORY.rst b/nfu_ecommerce/readme/HISTORY.rst
index e9a3e7c..f8cb7c8 100644
--- a/nfu_ecommerce/readme/HISTORY.rst
+++ b/nfu_ecommerce/readme/HISTORY.rst
@@ -1,2 +1,3 @@
:0.0.1: Initial module.
-:1.0.0: Live
\ No newline at end of file
+:1.0.0: Live
+:1.1.0: Add Open Packagings Filter
\ No newline at end of file
diff --git a/nfu_ecommerce/static/description/index.html b/nfu_ecommerce/static/description/index.html
index 6d36996..e1e683a 100644
--- a/nfu_ecommerce/static/description/index.html
+++ b/nfu_ecommerce/static/description/index.html
@@ -397,6 +397,8 @@ and after the current order.
| 1.0.0: | Live |
+| 1.1.0: | Add Open Packagings Filter |
+
diff --git a/nfu_ecommerce/views/templates.xml b/nfu_ecommerce/views/templates.xml
index 0b7b619..aa1070e 100644
--- a/nfu_ecommerce/views/templates.xml
+++ b/nfu_ecommerce/views/templates.xml
@@ -1,5 +1,24 @@
+
+
+
+
+ Open Packagings
+
+
+
+
+
+
+
+
+
+
diff --git a/nfu_sale_order_batch_packaging/models/sale_order_batch_product.py b/nfu_sale_order_batch_packaging/models/sale_order_batch_product.py
index f2c3cb8..db0a8db 100644
--- a/nfu_sale_order_batch_packaging/models/sale_order_batch_product.py
+++ b/nfu_sale_order_batch_packaging/models/sale_order_batch_product.py
@@ -4,7 +4,7 @@ from odoo import api, fields, models
class SaleOrderBatchProduct(models.Model):
_inherit = "sale.order.batch.product"
- open_packaging_qty = fields.Float(compute="_compute_open_packagin_qty")
+ open_packaging_qty = fields.Float(compute="_compute_open_packagin_qty", store=True)
@api.depends("sale_order_line_ids.product_uom_qty")
def _compute_open_packagin_qty(self):
From 50f0336d87202ce628c9fb7e72625bfaa04a688d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20G=C3=B6ttsch?=
Date: Fri, 4 Oct 2024 18:45:34 +0200
Subject: [PATCH 2/5] [FIX] devide between no open packages and no filter
---
nfu_ecommerce/controllers/main.py | 2 +-
nfu_ecommerce/models/product_template.py | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/nfu_ecommerce/controllers/main.py b/nfu_ecommerce/controllers/main.py
index 52dc815..bed77ec 100644
--- a/nfu_ecommerce/controllers/main.py
+++ b/nfu_ecommerce/controllers/main.py
@@ -48,6 +48,6 @@ class WebsiteSale(WebsiteSale):
)
post["open_product_ids"] = open_product_ids
else:
- post["open_product_ids"] = []
+ post["open_product_ids"] = None
res = super().shop(page=0, category=None, search="", min_price=0.0, max_price=0.0, ppg=False, **post)
return res
diff --git a/nfu_ecommerce/models/product_template.py b/nfu_ecommerce/models/product_template.py
index ab096e6..9ea29dc 100644
--- a/nfu_ecommerce/models/product_template.py
+++ b/nfu_ecommerce/models/product_template.py
@@ -16,6 +16,6 @@ class ProductTemplate(models.Model):
search_details = super()._search_get_detail(website, order, options)
open_product_ids = options.get("open_product_ids")
domain = search_details["base_domain"]
- if len(open_product_ids):
+ if open_product_ids is not None:
domain.append([("id", "in", tuple(open_product_ids))])
return search_details
From aa31ea501a9ca7ee100b1e07eb2e567ba7dd150d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20G=C3=B6ttsch?=
Date: Fri, 4 Oct 2024 19:35:38 +0200
Subject: [PATCH 3/5] [IMP] make Open Packaging a Toggle
---
nfu_ecommerce/controllers/main.py | 8 +++++++-
nfu_ecommerce/views/templates.xml | 14 ++++++++++----
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/nfu_ecommerce/controllers/main.py b/nfu_ecommerce/controllers/main.py
index bed77ec..899585e 100644
--- a/nfu_ecommerce/controllers/main.py
+++ b/nfu_ecommerce/controllers/main.py
@@ -14,6 +14,11 @@ class WebsiteSaleMinMax(WebsiteSale):
class WebsiteSale(WebsiteSale):
+ def _get_additional_shop_values(self, values):
+ new_values = super()._get_additional_shop_values(values)
+ new_values["open_packagings"] = True if request.httprequest.args.get("open_packagings") else False
+ return new_values
+
def _get_search_options(
self, category=None, attrib_values=None, pricelist=None, min_price=0.0, max_price=0.0, conversion_rate=1, **post
):
@@ -41,7 +46,8 @@ class WebsiteSale(WebsiteSale):
website=True,
)
def shop(self, page=0, category=None, search="", min_price=0.0, max_price=0.0, ppg=False, **post):
- if post.get("open_packagings"):
+ open_packages = bool(post.get("open_packagings"))
+ if open_packages:
batch = request.website.sale_get_order(force_create=True).batch_id
open_product_ids = (
batch.product_ids.filtered(lambda p: p.open_packaging_qty > 0).mapped("product_template_id").ids
diff --git a/nfu_ecommerce/views/templates.xml b/nfu_ecommerce/views/templates.xml
index aa1070e..99ccc7e 100644
--- a/nfu_ecommerce/views/templates.xml
+++ b/nfu_ecommerce/views/templates.xml
@@ -3,8 +3,11 @@
-
- Open Packagings
+
+
+ All Products
+ Open Packagings
+
@@ -12,8 +15,11 @@
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 4/5] [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:
Date: Mon, 7 Oct 2024 22:18:01 +0200
Subject: [PATCH 5/5] [IMP] nfu_ecommerce,nfu_sale_order_batch_packaging: use
python rounding to get rid of buggy float_round
---
nfu_ecommerce/models/sale_order_line.py | 9 ++-------
nfu_sale_order_batch_packaging/models/sale_order_line.py | 4 +++-
2 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/nfu_ecommerce/models/sale_order_line.py b/nfu_ecommerce/models/sale_order_line.py
index a3225fa..31b6b3f 100644
--- a/nfu_ecommerce/models/sale_order_line.py
+++ b/nfu_ecommerce/models/sale_order_line.py
@@ -1,5 +1,5 @@
from odoo import fields, models
-from odoo.tools import float_is_zero, float_repr, float_round
+from odoo.tools import float_is_zero, float_round
class SaleOrderLine(models.Model):
@@ -16,12 +16,7 @@ class SaleOrderLine(models.Model):
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))
+ line.open_qty = round(line.product_packaging_id.qty - qty_of_last_pack, precision_digits)
else:
line.open_qty = 0.0
else:
diff --git a/nfu_sale_order_batch_packaging/models/sale_order_line.py b/nfu_sale_order_batch_packaging/models/sale_order_line.py
index e01a175..d6ff040 100644
--- a/nfu_sale_order_batch_packaging/models/sale_order_line.py
+++ b/nfu_sale_order_batch_packaging/models/sale_order_line.py
@@ -28,13 +28,15 @@ class SaleOrderLine(models.Model):
if line.order_id.batch_id:
batch_id = line.batch_id
product_id = line.product_id
+ precision_rounding = line.product_id.uom_id.rounding
+ precision_digits = len(str(precision_rounding).split(".")[1])
batch_lines = (
self.env["sale.order.line"]
.sudo()
.search([("batch_id", "=", batch_id.id), ("product_id", "=", product_id.id)])
)
line.batch_uom_qty = sum(batch_lines.mapped("product_uom_qty"))
- line.batch_uom_max_qty = sum(batch_lines.mapped("product_uom_max_qty"))
+ line.batch_uom_max_qty = round(sum(batch_lines.mapped("product_uom_max_qty")), precision_digits)
else:
line.batch_uom_max_qty = line.batch_uom_qty = 0