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] [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 @@ + + + + +