[IMP] nfu_sale_order_batch_packaging: adjust webshop to new sale_order_batch fields

This commit is contained in:
Niels Göttsch 2025-03-27 22:22:08 +01:00 committed by madmooose
parent 7fbac3f4b7
commit f4b65e693c
2 changed files with 13 additions and 29 deletions

View file

@ -7,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(related="batch_product_id.product_uom_qty", string="Batch UOM Qty")
batch_uom_max_qty = fields.Float(related="batch_product_id.product_uom_max_qty", string="Batch UOM Max Qty")
@api.constrains("product_uom_qty", "product_uom_max_qty")
def _check_product_uom_qty(self):
@ -21,30 +21,6 @@ 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_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):
for vals in vals_list:

View file

@ -7,6 +7,16 @@ class SaleOrder(models.Model):
batch_id = fields.Many2one("sale.order.batch", copy=False, check_company=True, domain="[('state','!=','closed')]")
def _get_current_batch(self):
"""
Returns the current batch of the sale order.
:return: sale.order.batch
"""
self.ensure_one()
return self.env["sale.order.batch"].search(
[("state", "=", "open"), ("company_id", "=", self.company_id.id)], limit=1
)
def action_add_to_batch(self):
"""
TODO: Add Wizard to choose between batches if more than one existis. Picking the first one for now.
@ -14,10 +24,8 @@ class SaleOrder(models.Model):
for sale_order in self:
company = sale_order.company_id
sale_order = sale_order.with_company(company)
batch = self.env["sale.order.batch"].search(
[("state", "=", "open"), ("company_id", "=", company.id)], limit=1
)
if not sale_order.batch_id and sale_order.state in ["draft", "sent"]:
batch = sale_order._get_current_batch()
if not batch:
batch = sale_order.env["sale.order.batch"].create({})
sale_order.batch_id = batch