From 1a77c5ed98cdf6723cc68bba9be0c6a8b42811fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20G=C3=B6ttsch?= Date: Fri, 28 Mar 2025 16:27:14 +0100 Subject: [PATCH] [IMP] nfu_sale_order_batch_packaging: add open_max_qty --- nfu_sale_order_batch_packaging/README.rst | 3 +- .../__manifest__.py | 2 +- .../models/sale_order_batch_product.py | 46 ++++++++++++------- .../readme/HISTORY.rst | 3 +- .../static/description/index.html | 4 +- .../views/sale_order_batch_product_views.xml | 8 +++- 6 files changed, 44 insertions(+), 22 deletions(-) diff --git a/nfu_sale_order_batch_packaging/README.rst b/nfu_sale_order_batch_packaging/README.rst index 0c737d9..96ff7ae 100644 --- a/nfu_sale_order_batch_packaging/README.rst +++ b/nfu_sale_order_batch_packaging/README.rst @@ -38,7 +38,8 @@ Changelog :1.1.0: Live :1.2.0: Add regeneration action for batch products :1.2.1: refactoring -:1.3.0: add packagin states +:1.3.0: add packaging states +:1.3.1: add open_max_qty Bug Tracker =========== diff --git a/nfu_sale_order_batch_packaging/__manifest__.py b/nfu_sale_order_batch_packaging/__manifest__.py index 7578142..c6f2060 100644 --- a/nfu_sale_order_batch_packaging/__manifest__.py +++ b/nfu_sale_order_batch_packaging/__manifest__.py @@ -4,7 +4,7 @@ "author": "BAKEUP", "website": "https://www.bakeup.org", "category": "Sale", - "version": "16.0.1.3.0", + "version": "16.0.1.3.1", "depends": ["sale", "sale_order_batch"], "data": [ "views/sale_order_views.xml", diff --git a/nfu_sale_order_batch_packaging/models/sale_order_batch_product.py b/nfu_sale_order_batch_packaging/models/sale_order_batch_product.py index ceed397..fa673b1 100644 --- a/nfu_sale_order_batch_packaging/models/sale_order_batch_product.py +++ b/nfu_sale_order_batch_packaging/models/sale_order_batch_product.py @@ -8,33 +8,45 @@ class SaleOrderBatchProduct(models.Model): _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_state = fields.Selection(selection=PACKAGING_STATES, compute="_compute_open_packagin_state") + open_packaging_qty = fields.Float(compute="_compute_open_packaging_qty") + open_packaging_max_qty = fields.Float(compute="_compute_open_packaging_max_qty") + open_packaging_state = fields.Selection(selection=PACKAGING_STATES, compute="_compute_open_packaging_state") @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 = False + product.product_uom_max_qty = sum(product.sale_order_line_ids.mapped("product_uom_max_qty")) @api.depends("product_uom_qty") - def _compute_open_packagin_qty(self): + def _compute_open_packaging_qty(self): for product in self: - open_packaging_qty = product.product_packaging_qty - ( - product.product_uom_qty % product.product_packaging_qty - ) - product.open_packaging_qty = ( - 0 if open_packaging_qty == product.product_packaging_qty else open_packaging_qty - ) + if product.product_packaging_id: + open_packaging_qty = product.product_packaging_qty - ( + product.product_uom_qty % product.product_packaging_qty + ) + product.open_packaging_qty = ( + 0 if open_packaging_qty == product.product_packaging_qty else open_packaging_qty + ) + else: + product.open_packaging_qty = 0.0 + + @api.depends("product_uom_max_qty") + def _compute_open_packaging_max_qty(self): + for product in self: + if product.product_packaging_id: + if product.product_uom_max_qty < product.product_uom_qty + product.open_packaging_qty: + product.open_packaging_max_qty = product.product_packaging_qty - ( + product.product_uom_max_qty % product.product_packaging_qty + ) + else: + product.open_packaging_max_qty = 0.0 + else: + product.open_packaging_max_qty = 0.0 @api.depends("open_packaging_qty") - def _compute_open_packagin_state(self): + def _compute_open_packaging_state(self): for product in self: - if product.open_packaging_qty == 0: - product.open_packaging_state = "full" - elif (product.product_uom_max_qty - product.product_uom_qty) >= product.open_packaging_qty: + if product.open_packaging_qty == 0 or product.open_packaging_max_qty == 0: product.open_packaging_state = "full" elif product.product_uom_qty < product.product_packaging_qty: product.open_packaging_state = "open" diff --git a/nfu_sale_order_batch_packaging/readme/HISTORY.rst b/nfu_sale_order_batch_packaging/readme/HISTORY.rst index 9a4e888..b9882bb 100644 --- a/nfu_sale_order_batch_packaging/readme/HISTORY.rst +++ b/nfu_sale_order_batch_packaging/readme/HISTORY.rst @@ -3,4 +3,5 @@ :1.1.0: Live :1.2.0: Add regeneration action for batch products :1.2.1: refactoring -:1.3.0: add packagin states \ No newline at end of file +:1.3.0: add packaging states +:1.3.1: add open_max_qty \ No newline at end of file diff --git a/nfu_sale_order_batch_packaging/static/description/index.html b/nfu_sale_order_batch_packaging/static/description/index.html index 5b169be..97c524b 100644 --- a/nfu_sale_order_batch_packaging/static/description/index.html +++ b/nfu_sale_order_batch_packaging/static/description/index.html @@ -401,7 +401,9 @@ and adds a packaging default to sale order batch.

1.2.1:refactoring -1.3.0:add packagin states +1.3.0:add packaging states + +1.3.1:add open_max_qty diff --git a/nfu_sale_order_batch_packaging/views/sale_order_batch_product_views.xml b/nfu_sale_order_batch_packaging/views/sale_order_batch_product_views.xml index e8d7563..7624a11 100644 --- a/nfu_sale_order_batch_packaging/views/sale_order_batch_product_views.xml +++ b/nfu_sale_order_batch_packaging/views/sale_order_batch_product_views.xml @@ -6,7 +6,13 @@ - + + +