From 1544065c452230b4205e985b511b12cce75c8170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?NIels=20G=C3=B6ttsch?= Date: Mon, 2 Dec 2024 21:44:04 +0100 Subject: [PATCH] [imp] nfu_ecommerce: Add Open Packages to Product list --- nfu_ecommerce/README.rst | 3 +- nfu_ecommerce/__manifest__.py | 9 +++- nfu_ecommerce/controllers/main.py | 41 ++++++++++++++ nfu_ecommerce/readme/HISTORY.rst | 3 +- nfu_ecommerce/static/description/index.html | 2 + nfu_ecommerce/views/templates.xml | 54 +++++++++++++++++++ nfu_sale_order_batch_packaging/README.rst | 1 + .../__manifest__.py | 2 +- .../models/__init__.py | 2 + .../models/product_product.py | 11 ++++ .../models/product_template.py | 11 ++++ .../models/sale_order_batch_product.py | 29 ++++++++-- .../readme/HISTORY.rst | 3 +- .../static/description/index.html | 2 + .../views/sale_order_batch_views.xml | 3 ++ 15 files changed, 167 insertions(+), 9 deletions(-) create mode 100644 nfu_sale_order_batch_packaging/models/product_product.py create mode 100644 nfu_sale_order_batch_packaging/models/product_template.py diff --git a/nfu_ecommerce/README.rst b/nfu_ecommerce/README.rst index 3cc0636..ecc4d2c 100644 --- a/nfu_ecommerce/README.rst +++ b/nfu_ecommerce/README.rst @@ -38,8 +38,9 @@ Changelog :0.0.1: Initial module. :1.0.0: Live :1.1.0: Add Open Packagings Filter and fix rounding issue -:1.1.1: Pass arguments to super again :1.1.1: Make publish on website multi company +:1.1.2: Pass arguemnts to super again +:1.2.0: Add Open Packages to Product list Bug Tracker =========== diff --git a/nfu_ecommerce/__manifest__.py b/nfu_ecommerce/__manifest__.py index 699e5fc..28cbf67 100644 --- a/nfu_ecommerce/__manifest__.py +++ b/nfu_ecommerce/__manifest__.py @@ -4,8 +4,13 @@ "author": "BAKEUP", "website": "https://www.bakeup.org", "category": "website", - "version": "16.0.1.1.1", - "depends": ["website_sale", "nfu_sale_order_batch_packaging", "website_decimal_quantity"], + "version": "16.0.1.2.0", + "depends": [ + "website_sale", + "nfu_sale_order_batch_packaging", + "website_decimal_quantity", + "nfu_product_bnn_attributes", + ], "data": ["views/product_template_views.xml", "views/templates.xml"], "assets": {"web.assets_frontend": ["nfu_ecommerce/static/src/js/website_sale.js"]}, "license": "LGPL-3", diff --git a/nfu_ecommerce/controllers/main.py b/nfu_ecommerce/controllers/main.py index 217ba46..1d443da 100644 --- a/nfu_ecommerce/controllers/main.py +++ b/nfu_ecommerce/controllers/main.py @@ -1,5 +1,6 @@ from odoo import fields, http from odoo.http import request +from odoo.tools import lazy from odoo.addons.website_sale.controllers.main import WebsiteSale @@ -17,6 +18,46 @@ 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 + # ToDo: Add batch qtys if open batch + batch = request.website.sale_get_order(force_create=True).batch_id + batch_products = batch.product_ids.filtered(lambda p: p.product_packaging_id) + packaging_info = {} + for product in values.get("products").sudo().filtered(lambda p: p.packaging_ids): + batch_product = batch_products.filtered(lambda p: p.product_template_id == product) + if batch_product: + batch_product = batch_product[0] + packaging_info[product.id] = { + "state": batch_product.open_packaging_state, + "open_qty": batch_product.open_packaging_qty, + "package_qty": batch_product.product_packaging_qty, + } + else: + packaging = product.sudo()._get_nfu_packaging() + if packaging and packaging.qty > 1: + packaging_info[product.id] = {"state": False, "open_qty": 0, "package_qty": packaging.qty} + new_values["packaging_info"] = packaging_info + new_values["get_product_packagings"] = lambda product: lazy(lambda: packaging_info.get(product.id, False)) + return new_values + + def _prepare_product_values(self, product, category, search, **kwargs): + new_values = super()._prepare_product_values(product, category, search, **kwargs) + batch = request.website.sale_get_order(force_create=True).batch_id + batch_product = batch.product_ids.filtered( + lambda p: p.product_template_id == product and p.product_packaging_id + ) + packaging_info = {} + if batch_product: + batch_product = batch_product[0] + packaging_info = { + "state": batch_product.open_packaging_state, + "open_qty": batch_product.open_packaging_qty, + "package_qty": batch_product.product_packaging_qty, + } + else: + packaging = product.sudo()._get_nfu_packaging() + if packaging and packaging.qty > 1: + packaging_info = {"state": False, "open_qty": 0, "package_qty": packaging.qty} + new_values["packaging_info"] = packaging_info return new_values def _get_search_options( diff --git a/nfu_ecommerce/readme/HISTORY.rst b/nfu_ecommerce/readme/HISTORY.rst index 11c32a8..f680a1a 100644 --- a/nfu_ecommerce/readme/HISTORY.rst +++ b/nfu_ecommerce/readme/HISTORY.rst @@ -2,4 +2,5 @@ :1.0.0: Live :1.1.0: Add Open Packagings Filter and fix rounding issue :1.1.1: Pass arguments to super again -:1.1.1: Make publish on website multi company \ No newline at end of file +:1.1.2: Make publish on website multi company +:1.2.0: Add Open Packages to Product list \ No newline at end of file diff --git a/nfu_ecommerce/static/description/index.html b/nfu_ecommerce/static/description/index.html index 29cd34d..da69fbb 100644 --- a/nfu_ecommerce/static/description/index.html +++ b/nfu_ecommerce/static/description/index.html @@ -403,6 +403,8 @@ and after the current order.

1.1.1:Make publish on website multi company +1.2.0:Add Open Packages to Product list + diff --git a/nfu_ecommerce/views/templates.xml b/nfu_ecommerce/views/templates.xml index 49342c2..4cb7083 100644 --- a/nfu_ecommerce/views/templates.xml +++ b/nfu_ecommerce/views/templates.xml @@ -25,6 +25,60 @@ + + + +