diff --git a/nfu_ecommerce/README.rst b/nfu_ecommerce/README.rst index 68cbf26..1c8b81e 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 and fix rounding issue 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..899585e 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,49 @@ 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_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 + ): + 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): + 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 + ) + post["open_product_ids"] = open_product_ids + else: + 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/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/product_template.py b/nfu_ecommerce/models/product_template.py index b785776..9ea29dc 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 open_product_ids is not None: + domain.append([("id", "in", tuple(open_product_ids))]) + return search_details diff --git a/nfu_ecommerce/models/sale_order_line.py b/nfu_ecommerce/models/sale_order_line.py index 4f952a8..31b6b3f 100644 --- a/nfu_ecommerce/models/sale_order_line.py +++ b/nfu_ecommerce/models/sale_order_line.py @@ -1,11 +1,23 @@ -from odoo import models +from odoo import fields, models +from odoo.tools import float_is_zero, 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): + line.open_qty = round(line.product_packaging_id.qty - qty_of_last_pack, 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 e9a3e7c..5e4a8d0 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 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 6d36996..2f4c5c6 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 and fix rounding issue + diff --git a/nfu_ecommerce/views/templates.xml b/nfu_ecommerce/views/templates.xml index 0b7b619..49342c2 100644 --- a/nfu_ecommerce/views/templates.xml +++ b/nfu_ecommerce/views/templates.xml @@ -1,10 +1,39 @@ + + + + +