[WIP] nfu_ecommerce: add packacking qtys
This commit is contained in:
parent
9f35fc87e9
commit
344564a1d3
4 changed files with 29 additions and 63 deletions
|
|
@ -26,16 +26,18 @@ class WebsiteSale(WebsiteSale):
|
|||
batch_product = batch_products.filtered(lambda p: p.product_template_id == product)
|
||||
if batch_product:
|
||||
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] = {
|
||||
"state": batch_product.open_packaging_state,
|
||||
"state_color": state_color,
|
||||
"open_qty": batch_product.open_packaging_qty,
|
||||
"open_max_qty": batch_product.open_packaging_max_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
|
||||
|
|
|
|||
|
|
@ -1,3 +1,2 @@
|
|||
from . import product_template
|
||||
from . import sale_order
|
||||
from . import sale_order_line
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -39,20 +39,6 @@
|
|||
active="True"
|
||||
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">
|
||||
<t t-if="any([product[field.name] for field in website.shop_extra_field_ids])">
|
||||
<p class="text-muted">
|
||||
|
|
@ -132,16 +118,7 @@
|
|||
<template id="cart_lines_packaging" inherit_id="website_sale.cart_lines" name="Shopping Cart Lines">
|
||||
<xpath expr="//td[hasclass('td-product_name')]" position="inside">
|
||||
<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
|
||||
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 < line.product_packaging_id.qty else ''}"
|
||||
/></span>
|
||||
<span>Packaging Size: <t t-esc="line.product_packaging_id.qty"/></span>
|
||||
</div>
|
||||
</xpath>
|
||||
<xpath expr="//th[hasclass('td-qty')]" position="after">
|
||||
|
|
@ -151,6 +128,24 @@
|
|||
</t>
|
||||
</th>
|
||||
</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>
|
||||
(+ <t t-out="line.batch_product_id.open_packaging_qty"/>)
|
||||
</div>
|
||||
</xpath>
|
||||
<xpath expr="//td[hasclass('td-qty')]" position="after">
|
||||
<td class="text-center td-qty">
|
||||
<div class="css_quantity input-group mx-auto justify-content-center">
|
||||
|
|
@ -214,6 +209,9 @@
|
|||
/>
|
||||
</t>
|
||||
</div>
|
||||
<div>
|
||||
(+ <t t-out="line.batch_product_id.open_packaging_max_qty"/>)
|
||||
</div>
|
||||
</td>
|
||||
</xpath>
|
||||
</template>
|
||||
|
|
@ -230,16 +228,6 @@
|
|||
</template>
|
||||
|
||||
<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 < line.product_packaging_id.qty else ''}"
|
||||
/></span>
|
||||
</div>
|
||||
</xpath>
|
||||
<xpath expr="//th[hasclass('td-qty')]" position="after">
|
||||
<th class="border-top-0 td-qty">Max Qty</th>
|
||||
</xpath>
|
||||
|
|
|
|||
Loading…
Reference in a new issue