[WIP] nfu_ecommerce: add packacking qtys

This commit is contained in:
Niels Göttsch 2025-03-28 16:27:59 +01:00 committed by madmooose
parent 9f35fc87e9
commit 344564a1d3
4 changed files with 29 additions and 63 deletions

View file

@ -26,16 +26,18 @@ class WebsiteSale(WebsiteSale):
batch_product = batch_products.filtered(lambda p: p.product_template_id == product) batch_product = batch_products.filtered(lambda p: p.product_template_id == product)
if batch_product: if batch_product:
batch_product = batch_product[0] batch_product = batch_product[0]
if batch_product.open_packaging_state == "full":
state_color = "green"
elif batch_product.open_packaging_state == "last_open":
state_color = "#ff6700"
else:
state_color = "red"
packaging_info[product.id] = { packaging_info[product.id] = {
"state": batch_product.open_packaging_state, "state_color": state_color,
"open_qty": batch_product.open_packaging_qty, "open_qty": batch_product.open_packaging_qty,
"open_max_qty": batch_product.open_packaging_max_qty, "open_max_qty": batch_product.open_packaging_max_qty,
"package_qty": batch_product.product_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["packaging_info"] = packaging_info
new_values["get_product_packagings"] = lambda product: lazy(lambda: packaging_info.get(product.id, False)) new_values["get_product_packagings"] = lambda product: lazy(lambda: packaging_info.get(product.id, False))
return new_values return new_values

View file

@ -1,3 +1,2 @@
from . import product_template from . import product_template
from . import sale_order from . import sale_order
from . import sale_order_line

View file

@ -1,23 +0,0 @@
from odoo import fields, models
from odoo.tools import float_is_zero, float_round
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
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

View file

@ -39,20 +39,6 @@
active="True" active="True"
name="Show Extra Fields" name="Show Extra Fields"
> >
<xpath expr="//div[hasclass('oe_product_image')]" position="before">
<t t-set="template_packaging_vals" t-value="get_product_packagings(product)"/>
<t t-if="template_packaging_vals">
<t
t-set="packaging_ribbon_color"
t-value="'green' if template_packaging_vals['state'] == 'full'
else 'red'"
/>
<span
t-attf-class="o_ribbon o_not_editable o_ribbon_right"
t-att-style="'color: white; background-color: %s;' % packaging_ribbon_color"
>+5/+3</span>
</t>
</xpath>
<xpath expr="//div[hasclass('o_wsale_product_information_text')]" position="after"> <xpath expr="//div[hasclass('o_wsale_product_information_text')]" position="after">
<t t-if="any([product[field.name] for field in website.shop_extra_field_ids])"> <t t-if="any([product[field.name] for field in website.shop_extra_field_ids])">
<p class="text-muted"> <p class="text-muted">
@ -132,16 +118,7 @@
<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)">
<span t-if="line.open_qty > 0">Open Package: <t t-esc="line.open_qty"/>/<t <span>Packaging Size: <t t-esc="line.product_packaging_id.qty"/></span>
t-esc="line.product_packaging_id.qty"
/>
</span>
<span t-else="">No open package available</span>
<br/>
<span>Max Ordered Quantity: <span
t-esc="line.batch_uom_max_qty"
t-attf-class="#{'text-danger' if line.batch_uom_max_qty &lt; line.product_packaging_id.qty else ''}"
/></span>
</div> </div>
</xpath> </xpath>
<xpath expr="//th[hasclass('td-qty')]" position="after"> <xpath expr="//th[hasclass('td-qty')]" position="after">
@ -151,6 +128,24 @@
</t> </t>
</th> </th>
</xpath> </xpath>
<xpath expr="//td[hasclass('td-qty')]" position="attributes">
<!-- TODO: Fix if-statement -->
<attribute
t-if="line.batch_product_id.open_packaging_state == 'open'"
name="style"
>background-color: red;</attribute>
<attribute
t-if="line.batch_product_id.open_packaging_state == 'last_open'"
name="style"
>background-color: orange;</attribute>
</xpath>
<xpath expr="//td[hasclass('td-qty')]" position="inside">
<div>
&#40;+ <t t-out="line.batch_product_id.open_packaging_qty"/>&#41;
</div>
</xpath>
<xpath expr="//td[hasclass('td-qty')]" position="after"> <xpath expr="//td[hasclass('td-qty')]" position="after">
<td class="text-center td-qty"> <td class="text-center td-qty">
<div class="css_quantity input-group mx-auto justify-content-center"> <div class="css_quantity input-group mx-auto justify-content-center">
@ -214,6 +209,9 @@
/> />
</t> </t>
</div> </div>
<div>
&#40;+ <t t-out="line.batch_product_id.open_packaging_max_qty"/>&#41;
</div>
</td> </td>
</xpath> </xpath>
</template> </template>
@ -230,16 +228,6 @@
</template> </template>
<template id="cart_summary_packaging" inherit_id="website_sale.cart_summary" name="Cart right column"> <template id="cart_summary_packaging" inherit_id="website_sale.cart_summary" name="Cart right column">
<xpath expr="//td[hasclass('td-product_name')]" position="inside">
<div t-if="line.product_packaging_id and (line.product_packaging_id.qty != 1)">
<span>Open Package: <t t-esc="line.compute_open_packages()"/>/<t t-esc="line.product_packaging_id.qty"/>
</span><br/>
<span>Max Ordered Quantity: <span
t-esc="line.batch_uom_max_qty"
t-attf-class="#{'text-danger' if line.batch_uom_max_qty &lt; line.product_packaging_id.qty else ''}"
/></span>
</div>
</xpath>
<xpath expr="//th[hasclass('td-qty')]" position="after"> <xpath expr="//th[hasclass('td-qty')]" position="after">
<th class="border-top-0 td-qty">Max Qty</th> <th class="border-top-0 td-qty">Max Qty</th>
</xpath> </xpath>