[wip] nfu_sale_order_batch_packaging: fix calculation
This commit is contained in:
parent
06a114bffc
commit
d31e45814a
5 changed files with 39 additions and 41 deletions
|
|
@ -1,5 +1,4 @@
|
|||
from . import product_product
|
||||
from . import product_template
|
||||
from . import sale_order_batch
|
||||
from . import sale_order_line
|
||||
from . import sale_order_batch_product
|
||||
from . import sale_order_line
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class SaleOrderBatchProduct(models.Model):
|
|||
|
||||
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_state = fields.Selection(selection=PACKAGING_STATES, compute="_compute_open_packagin_state")
|
||||
# open_packaging_state = fields.Selection(selection=PACKAGING_STATES, compute="_compute_open_packagin_state")
|
||||
|
||||
@api.depends("sale_order_line_ids.product_uom_max_qty")
|
||||
def _compute_product_uom_max_qty(self):
|
||||
|
|
@ -29,15 +29,15 @@ class SaleOrderBatchProduct(models.Model):
|
|||
0 if open_packaging_qty == product.product_packaging_qty else open_packaging_qty
|
||||
)
|
||||
|
||||
@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.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
|
||||
def create(self, vals_list):
|
||||
|
|
@ -46,5 +46,6 @@ class SaleOrderBatchProduct(models.Model):
|
|||
packaging = (
|
||||
self.env["product.product"].search([("id", "=", vals.get("product_id"))])._get_nfu_packaging()
|
||||
)
|
||||
if packaging:
|
||||
vals["product_packaging_id"] = packaging.id
|
||||
return super().create(vals_list)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tools import float_round
|
||||
|
||||
|
||||
class SaleOrderLine(models.Model):
|
||||
|
|
@ -8,8 +7,8 @@ class SaleOrderLine(models.Model):
|
|||
|
||||
product_uom_ordered_qty = fields.Float(string="Ordered Qty", digits="Product Unit of Measure", default=1.0)
|
||||
product_uom_max_qty = fields.Float(string="Max Qty", digits="Product Unit of Measure")
|
||||
batch_uom_qty = fields.Float(compute="_compute_batch_uom_qty")
|
||||
batch_uom_max_qty = fields.Float(compute="_compute_batch_uom_qty")
|
||||
# batch_uom_qty = fields.Float(compute="_compute_batch_uom_qty")
|
||||
# batch_uom_max_qty = fields.Float(compute="_compute_batch_uom_qty")
|
||||
|
||||
@api.constrains("product_uom_qty", "product_uom_max_qty")
|
||||
def _check_product_uom_qty(self):
|
||||
|
|
@ -22,29 +21,29 @@ class SaleOrderLine(models.Model):
|
|||
)
|
||||
)
|
||||
|
||||
@api.depends("product_uom_qty", "product_uom_max_qty")
|
||||
def _compute_batch_uom_qty(self):
|
||||
for line in self:
|
||||
if line.batch_product_id:
|
||||
line.batch_uom_qty = line.batch_product_id.product_uom_qty
|
||||
line.batch_uom_max_qty = line.batch_product_id.product_uom_max_qty
|
||||
else:
|
||||
line.batch_uom_max_qty = line.batch_uom_qty = 0
|
||||
# @api.depends("product_uom_qty", "product_uom_max_qty")
|
||||
# def _compute_batch_uom_qty(self):
|
||||
# for line in self:
|
||||
# if line.batch_product_id:
|
||||
# line.batch_uom_qty = line.batch_product_id.product_uom_qty
|
||||
# line.batch_uom_max_qty = line.batch_product_id.product_uom_max_qty
|
||||
# else:
|
||||
# line.batch_uom_max_qty = line.batch_uom_qty = 0
|
||||
|
||||
@api.depends("product_packaging_id", "product_uom", "product_uom_qty", "batch_id")
|
||||
def _compute_product_packaging_qty(self):
|
||||
for line in self:
|
||||
if not line.product_packaging_id:
|
||||
line.product_packaging_qty = False
|
||||
elif line.batch_id:
|
||||
packaging_uom = line.product_packaging_id.product_uom_id
|
||||
batch_uom_qty = line.product_uom._compute_quantity(line.batch_uom_qty, packaging_uom)
|
||||
line.product_packaging_qty = float_round(
|
||||
batch_uom_qty / line.product_packaging_id.qty, precision_rounding=packaging_uom.rounding
|
||||
)
|
||||
else:
|
||||
super()._compute_product_packaging_qty()
|
||||
return True
|
||||
# @api.depends("product_packaging_id", "product_uom", "product_uom_qty", "batch_id")
|
||||
# def _compute_product_packaging_qty(self):
|
||||
# for line in self:
|
||||
# if not line.product_packaging_id:
|
||||
# line.product_packaging_qty = False
|
||||
# elif line.batch_id:
|
||||
# packaging_uom = line.product_packaging_id.product_uom_id
|
||||
# batch_uom_qty = line.product_uom._compute_quantity(line.batch_uom_qty, packaging_uom)
|
||||
# line.product_packaging_qty = float_round(
|
||||
# batch_uom_qty / line.product_packaging_id.qty, precision_rounding=packaging_uom.rounding
|
||||
# )
|
||||
# else:
|
||||
# super()._compute_product_packaging_qty()
|
||||
# return True
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
|
|
|
|||
|
|
@ -18,10 +18,10 @@
|
|||
<field name="product_uom_max_qty"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='product_ids']/tree" position="inside">
|
||||
<field name="open_packaging_qty" invisiable="True"/>
|
||||
<field name="open_packaging_qty" invisiable="1"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='product_ids']/tree/field[@name='product_uom_qty']" position="after">
|
||||
<field name="product_uom_max_qty" invisiable="True"/>
|
||||
<field name="product_uom_max_qty"/>
|
||||
</xpath>
|
||||
<xpath
|
||||
expr="//field[@name='product_ids']/tree/field[@name='product_template_id']"
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@
|
|||
</xpath>
|
||||
<xpath expr="//field[@name='order_line']/tree/field[@name='product_uom_qty']" position="after">
|
||||
<field name="product_uom_max_qty"/>
|
||||
<field name="batch_uom_qty"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
|
|
|||
Loading…
Reference in a new issue