[IMP] Add Open Packagings Filter to Webshop

This commit is contained in:
Niels Göttsch 2024-10-04 17:42:38 +02:00
parent 786c59851b
commit 978011520c
8 changed files with 75 additions and 3 deletions

View file

@ -37,6 +37,7 @@ Changelog
:0.0.1: Initial module. :0.0.1: Initial module.
:1.0.0: Live :1.0.0: Live
:1.1.0: Add Open Packagings Filter
Bug Tracker Bug Tracker
=========== ===========

View file

@ -4,7 +4,7 @@
"author": "BAKEUP", "author": "BAKEUP",
"website": "https://www.bakeup.org", "website": "https://www.bakeup.org",
"category": "website", "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"], "depends": ["website_sale", "nfu_sale_order_batch_packaging", "website_decimal_quantity"],
"data": ["views/product_template_views.xml", "views/templates.xml"], "data": ["views/product_template_views.xml", "views/templates.xml"],
"assets": {"web.assets_frontend": ["nfu_ecommerce/static/src/js/website_sale.js"]}, "assets": {"web.assets_frontend": ["nfu_ecommerce/static/src/js/website_sale.js"]},

View file

@ -1,4 +1,5 @@
from odoo import fields, http from odoo import fields, http
from odoo.http import request
from odoo.addons.website_sale.controllers.main import WebsiteSale 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_ordered_qty = fields.Float(ordered_qty)
product_uom_max_qty = fields.Float(max_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) 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/<int:page>",
'/shop/category/<model("product.public.category"):category>',
'/shop/category/<model("product.public.category"):category>/page/<int: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

View file

@ -11,3 +11,11 @@ class ProductTemplate(models.Model):
def action_unpublish_on_website(self): def action_unpublish_on_website(self):
for product in self: for product in self:
product.is_published = False 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

View file

@ -1,2 +1,3 @@
:0.0.1: Initial module. :0.0.1: Initial module.
:1.0.0: Live :1.0.0: Live
:1.1.0: Add Open Packagings Filter

View file

@ -397,6 +397,8 @@ and after the current order.</p>
</tr> </tr>
<tr class="field"><th class="field-name">1.0.0:</th><td class="field-body">Live</td> <tr class="field"><th class="field-name">1.0.0:</th><td class="field-body">Live</td>
</tr> </tr>
<tr class="field"><th class="field-name">1.1.0:</th><td class="field-body">Add Open Packagings Filter</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>

View file

@ -1,5 +1,24 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<odoo> <odoo>
<template id="products_open_packaging" inherit_id="website_sale.products">
<xpath expr="//aside[@id='products_grid_before']/div[1]/div[1]" position="before">
<a t-att-href="keep('/shop',open_packagings = True)">
<h6 t-attf-class="o_packaging_collapse_title mb-3 {{_titleClasses}}"><b>Open Packagings</b></h6>
</a>
</xpath>
</template>
<template id="o_wsale_offcanvas" name="Open Packagings" inherit_id="website_sale.o_wsale_offcanvas">
<xpath expr="//div[@id='o_wsale_offcanvas_content']/div[1]" position="before">
<div class="position-relative o_wsale_offcanvas_title px-4 border-top">
<a t-att-href="keep('/shop',open_packagings = True)">
<h6 t-attf-class="o_packaging_collapse_title mb-3 pt-3 {{_titleClasses}}"><b>Open Packagings</b></h6>
</a>
</div>
</xpath>
</template>
<template id="cart_lines_packaging" inherit_id="website_sale.cart_lines" name="Shopping Cart Lines"> <template id="cart_lines_packaging" inherit_id="website_sale.cart_lines" name="Shopping Cart Lines">
<xpath expr="//td[hasclass('td-product_name')]" position="inside"> <xpath expr="//td[hasclass('td-product_name')]" position="inside">
<div t-if="line.product_packaging_id and (line.product_packaging_id.qty != 1)"> <div t-if="line.product_packaging_id and (line.product_packaging_id.qty != 1)">

View file

@ -4,7 +4,7 @@ from odoo import api, fields, models
class SaleOrderBatchProduct(models.Model): class SaleOrderBatchProduct(models.Model):
_inherit = "sale.order.batch.product" _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") @api.depends("sale_order_line_ids.product_uom_qty")
def _compute_open_packagin_qty(self): def _compute_open_packagin_qty(self):