From f4b65e693c6ad94483cac3a95586b892f65f76fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20G=C3=B6ttsch?= Date: Thu, 27 Mar 2025 22:22:08 +0100 Subject: [PATCH] [IMP] nfu_sale_order_batch_packaging: adjust webshop to new sale_order_batch fields --- .../models/sale_order_line.py | 28 ++----------------- sale_order_batch/models/sale_order.py | 14 ++++++++-- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/nfu_sale_order_batch_packaging/models/sale_order_line.py b/nfu_sale_order_batch_packaging/models/sale_order_line.py index c3deff5..7fec07e 100644 --- a/nfu_sale_order_batch_packaging/models/sale_order_line.py +++ b/nfu_sale_order_batch_packaging/models/sale_order_line.py @@ -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: diff --git a/sale_order_batch/models/sale_order.py b/sale_order_batch/models/sale_order.py index 130ddfe..46c2f56 100644 --- a/sale_order_batch/models/sale_order.py +++ b/sale_order_batch/models/sale_order.py @@ -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