[imp] nfu_ecommerce: Add Open Packages to Product list
This commit is contained in:
parent
86becfbd22
commit
1544065c45
15 changed files with 167 additions and 9 deletions
|
|
@ -38,8 +38,9 @@ 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 and fix rounding issue
|
: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.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
|
Bug Tracker
|
||||||
===========
|
===========
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,13 @@
|
||||||
"author": "BAKEUP",
|
"author": "BAKEUP",
|
||||||
"website": "https://www.bakeup.org",
|
"website": "https://www.bakeup.org",
|
||||||
"category": "website",
|
"category": "website",
|
||||||
"version": "16.0.1.1.1",
|
"version": "16.0.1.2.0",
|
||||||
"depends": ["website_sale", "nfu_sale_order_batch_packaging", "website_decimal_quantity"],
|
"depends": [
|
||||||
|
"website_sale",
|
||||||
|
"nfu_sale_order_batch_packaging",
|
||||||
|
"website_decimal_quantity",
|
||||||
|
"nfu_product_bnn_attributes",
|
||||||
|
],
|
||||||
"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"]},
|
||||||
"license": "LGPL-3",
|
"license": "LGPL-3",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
from odoo import fields, http
|
from odoo import fields, http
|
||||||
from odoo.http import request
|
from odoo.http import request
|
||||||
|
from odoo.tools import lazy
|
||||||
|
|
||||||
from odoo.addons.website_sale.controllers.main import WebsiteSale
|
from odoo.addons.website_sale.controllers.main import WebsiteSale
|
||||||
|
|
||||||
|
|
@ -17,6 +18,46 @@ class WebsiteSale(WebsiteSale):
|
||||||
def _get_additional_shop_values(self, values):
|
def _get_additional_shop_values(self, values):
|
||||||
new_values = super()._get_additional_shop_values(values)
|
new_values = super()._get_additional_shop_values(values)
|
||||||
new_values["open_packagings"] = True if request.httprequest.args.get("open_packagings") else False
|
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
|
return new_values
|
||||||
|
|
||||||
def _get_search_options(
|
def _get_search_options(
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,5 @@
|
||||||
:1.0.0: Live
|
:1.0.0: Live
|
||||||
:1.1.0: Add Open Packagings Filter and fix rounding issue
|
:1.1.0: Add Open Packagings Filter and fix rounding issue
|
||||||
:1.1.1: Pass arguments to super again
|
:1.1.1: Pass arguments to super again
|
||||||
:1.1.1: Make publish on website multi company
|
:1.1.2: Make publish on website multi company
|
||||||
|
:1.2.0: Add Open Packages to Product list
|
||||||
|
|
@ -403,6 +403,8 @@ and after the current order.</p>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="field"><th class="field-name">1.1.1:</th><td class="field-body">Make publish on website multi company</td>
|
<tr class="field"><th class="field-name">1.1.1:</th><td class="field-body">Make publish on website multi company</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr class="field"><th class="field-name">1.2.0:</th><td class="field-body">Add Open Packages to Product list</td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,60 @@
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template
|
||||||
|
id="ecom_show_extra_fields_products_item"
|
||||||
|
inherit_id="website_sale.products_item"
|
||||||
|
active="True"
|
||||||
|
name="Show Extra Fields"
|
||||||
|
>
|
||||||
|
<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">
|
||||||
|
<t t-foreach='website.shop_extra_field_ids' t-as='field' t-if='product[field.name]'>
|
||||||
|
<b><t t-esc='field.label'/>: </b>
|
||||||
|
<t t-if='field.field_id.ttype != "binary"'>
|
||||||
|
<span t-esc='product[field.name]' t-options="{'widget': field.field_id.ttype}"/>
|
||||||
|
</t>
|
||||||
|
<t t-else=''>
|
||||||
|
<a
|
||||||
|
target='_blank'
|
||||||
|
t-attf-href='/web/content/product.template/#{product.id}/#{field.name}?download=1'
|
||||||
|
>
|
||||||
|
<i class='fa fa-file'/>
|
||||||
|
</a>
|
||||||
|
</t>
|
||||||
|
<br/>
|
||||||
|
</t>
|
||||||
|
<t t-set="template_packaging_vals" t-value="get_product_packagings(product)"/>
|
||||||
|
<t t-if="template_packaging_vals">
|
||||||
|
<b>Open Qty: </b><span t-esc="template_packaging_vals['open_qty']"/>/<span
|
||||||
|
t-esc="template_packaging_vals['package_qty']"
|
||||||
|
/><br/>
|
||||||
|
<t t-if="template_packaging_vals['state']">
|
||||||
|
<b>State: </b><span t-esc="template_packaging_vals['state']"/>
|
||||||
|
<br/>
|
||||||
|
</t>
|
||||||
|
</t>
|
||||||
|
</p>
|
||||||
|
</t>
|
||||||
|
</xpath>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template id="product_packagings" inherit_id="website_sale.product">
|
||||||
|
<xpath expr="//p[@t-field='product.description_sale']" position="after">
|
||||||
|
<div t-if="packaging_info">
|
||||||
|
<b>Open Qty: </b><span t-esc="packaging_info['open_qty']"/>/<span
|
||||||
|
t-esc="packaging_info['package_qty']"
|
||||||
|
/>
|
||||||
|
<br/>
|
||||||
|
<t t-if="packaging_info['state']">
|
||||||
|
<b>State: </b><span t-esc="packaging_info['state']"/>
|
||||||
|
<br/>
|
||||||
|
</t>
|
||||||
|
</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)">
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ Changelog
|
||||||
:1.0.0: rename to nfu_sale_order_batch_packaging
|
:1.0.0: rename to nfu_sale_order_batch_packaging
|
||||||
:1.1.0: Live
|
:1.1.0: Live
|
||||||
:1.2.0: Add regeneration action for batch products
|
:1.2.0: Add regeneration action for batch products
|
||||||
|
:1.2.1: refactoring
|
||||||
|
|
||||||
Bug Tracker
|
Bug Tracker
|
||||||
===========
|
===========
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
"author": "BAKEUP",
|
"author": "BAKEUP",
|
||||||
"website": "https://www.bakeup.org",
|
"website": "https://www.bakeup.org",
|
||||||
"category": "Sale",
|
"category": "Sale",
|
||||||
"version": "16.0.1.2.0",
|
"version": "16.0.1.2.1",
|
||||||
"depends": ["sale", "sale_order_batch"],
|
"depends": ["sale", "sale_order_batch"],
|
||||||
"data": [
|
"data": [
|
||||||
"views/sale_order_views.xml",
|
"views/sale_order_views.xml",
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
from . import product_product
|
||||||
|
from . import product_template
|
||||||
from . import sale_order_batch
|
from . import sale_order_batch
|
||||||
from . import sale_order_line
|
from . import sale_order_line
|
||||||
from . import sale_order_batch_product
|
from . import sale_order_batch_product
|
||||||
|
|
|
||||||
11
nfu_sale_order_batch_packaging/models/product_product.py
Normal file
11
nfu_sale_order_batch_packaging/models/product_product.py
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
from odoo import models
|
||||||
|
|
||||||
|
|
||||||
|
class ProductProduct(models.Model):
|
||||||
|
_inherit = "product.product"
|
||||||
|
|
||||||
|
def _get_nfu_packaging(self):
|
||||||
|
self.ensure_one()
|
||||||
|
if self.packaging_ids:
|
||||||
|
return self.packaging_ids[0]
|
||||||
|
return False
|
||||||
11
nfu_sale_order_batch_packaging/models/product_template.py
Normal file
11
nfu_sale_order_batch_packaging/models/product_template.py
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
from odoo import models
|
||||||
|
|
||||||
|
|
||||||
|
class ProductTemplate(models.Model):
|
||||||
|
_inherit = "product.template"
|
||||||
|
|
||||||
|
def _get_nfu_packaging(self):
|
||||||
|
self.ensure_one()
|
||||||
|
if self.packaging_ids:
|
||||||
|
return self.packaging_ids[0]
|
||||||
|
return False
|
||||||
|
|
@ -1,10 +1,15 @@
|
||||||
from odoo import api, fields, models
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
|
||||||
|
PACKAGING_STATES = [("open", "Open"), ("full", "Full"), ("last_open", "Last package open")]
|
||||||
|
|
||||||
|
|
||||||
class SaleOrderBatchProduct(models.Model):
|
class SaleOrderBatchProduct(models.Model):
|
||||||
_inherit = "sale.order.batch.product"
|
_inherit = "sale.order.batch.product"
|
||||||
|
|
||||||
|
product_uom_max_qty = fields.Float("Max Qty", compute="_compute_product_uom_max_qty")
|
||||||
open_packaging_qty = fields.Float(compute="_compute_open_packagin_qty", store=True)
|
open_packaging_qty = fields.Float(compute="_compute_open_packagin_qty", store=True)
|
||||||
|
open_packaging_state = fields.Selection(selection=PACKAGING_STATES, compute="_compute_open_packagin_state")
|
||||||
|
|
||||||
@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):
|
||||||
|
|
@ -16,12 +21,30 @@ class SaleOrderBatchProduct(models.Model):
|
||||||
0 if open_packaging_qty == product.product_packaging_qty else open_packaging_qty
|
0 if open_packaging_qty == product.product_packaging_qty else open_packaging_qty
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@api.depends("sale_order_line_ids.product_uom_max_qty")
|
||||||
|
def _compute_product_uom_max_qty(self):
|
||||||
|
for product in self:
|
||||||
|
if product.sale_order_line_ids:
|
||||||
|
product.product_uom_max_qty = sum(product.sale_order_line_ids.mapped("product_uom_max_qty"))
|
||||||
|
else:
|
||||||
|
product.product_uom_max_qty = 0
|
||||||
|
|
||||||
|
@api.depends("open_packaging_qty", "product_packaging_qty")
|
||||||
|
def _compute_open_packagin_state(self):
|
||||||
|
for product in self:
|
||||||
|
if product.open_packaging_qty == 0:
|
||||||
|
product.open_packaging_state = "full"
|
||||||
|
elif product.open_packaging_qty < product.product_packaging_qty:
|
||||||
|
product.open_packaging_state = "open"
|
||||||
|
else:
|
||||||
|
product.open_packaging_state = "last_open"
|
||||||
|
|
||||||
@api.model_create_multi
|
@api.model_create_multi
|
||||||
def create(self, vals_list):
|
def create(self, vals_list):
|
||||||
for vals in vals_list:
|
for vals in vals_list:
|
||||||
|
|
||||||
if vals.get("product_id") and not vals.get("product_packaging_id"):
|
if vals.get("product_id") and not vals.get("product_packaging_id"):
|
||||||
product_id = vals.get("product_id")
|
packaging = (
|
||||||
packaging = self.env["product.packaging"].search([("product_id", "=", product_id)], limit=1)
|
self.env["product.product"].search([("id", "=", vals.get("product_id"))])._get_nfu_packaging()
|
||||||
|
)
|
||||||
vals["product_packaging_id"] = packaging.id
|
vals["product_packaging_id"] = packaging.id
|
||||||
return super().create(vals_list)
|
return super().create(vals_list)
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,4 @@
|
||||||
:1.0.0: rename to nfu_sale_order_batch_packaging
|
:1.0.0: rename to nfu_sale_order_batch_packaging
|
||||||
:1.1.0: Live
|
:1.1.0: Live
|
||||||
:1.2.0: Add regeneration action for batch products
|
:1.2.0: Add regeneration action for batch products
|
||||||
|
:1.2.1: refactoring
|
||||||
|
|
@ -399,6 +399,8 @@ and adds a packaging default to sale order batch.</p>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="field"><th class="field-name">1.2.0:</th><td class="field-body">Add regeneration action for batch products</td>
|
<tr class="field"><th class="field-name">1.2.0:</th><td class="field-body">Add regeneration action for batch products</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr class="field"><th class="field-name">1.2.1:</th><td class="field-body">refactoring</td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,9 @@
|
||||||
<xpath expr="//field[@name='product_ids']/tree" position="inside">
|
<xpath expr="//field[@name='product_ids']/tree" position="inside">
|
||||||
<field name="open_packaging_qty" invisiable="True"/>
|
<field name="open_packaging_qty" invisiable="True"/>
|
||||||
</xpath>
|
</xpath>
|
||||||
|
<xpath expr="//field[@name='product_ids']/tree/field[@name='product_uom_qty']" position="after">
|
||||||
|
<field name="product_uom_max_qty" invisiable="True"/>
|
||||||
|
</xpath>
|
||||||
<xpath
|
<xpath
|
||||||
expr="//field[@name='product_ids']/tree/field[@name='product_template_id']"
|
expr="//field[@name='product_ids']/tree/field[@name='product_template_id']"
|
||||||
position="attributes"
|
position="attributes"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue