From 57bb70b6c716f5cd91b3c8e19d582cb65c93b8db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20G=C3=B6ttsch?= Date: Fri, 9 May 2025 16:20:12 +0200 Subject: [PATCH] [FIX] nfu_sale_order_batch_packaging: make open_packaging_qty sortable --- nfu_sale_order_batch_packaging/README.rst | 4 +++ .../__manifest__.py | 2 +- .../models/sale_order_batch_product.py | 2 +- .../models/sale_order_line.py | 5 ++- .../readme/HISTORY.rst | 6 +++- .../static/description/index.html | 34 ++++++++++++++----- .../models/sale_order_batch_product.py | 2 +- 7 files changed, 41 insertions(+), 14 deletions(-) diff --git a/nfu_sale_order_batch_packaging/README.rst b/nfu_sale_order_batch_packaging/README.rst index 8110cad..fd34d1f 100644 --- a/nfu_sale_order_batch_packaging/README.rst +++ b/nfu_sale_order_batch_packaging/README.rst @@ -42,6 +42,10 @@ Changelog :1.3.1: add open_max_qty :1.3.2: fix color indicator :1.3.3: Enable packagings on installation +:1.3.4: + - on creation set max_qty to product_uom_qty if not set + - remove zero exception for max_qty + - store open_packaging_qty on batch product module to make it sortable Bug Tracker =========== diff --git a/nfu_sale_order_batch_packaging/__manifest__.py b/nfu_sale_order_batch_packaging/__manifest__.py index c9c9e64..09352c6 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.3", + "version": "16.0.1.3.4", "depends": ["sale", "sale_order_batch"], "data": [ "data/ir_config_parameter.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 fa673b1..53c4c03 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,7 +8,7 @@ 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_packaging_qty") + open_packaging_qty = fields.Float(compute="_compute_open_packaging_qty", store=True) 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") 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 7fec07e..4c6bc90 100644 --- a/nfu_sale_order_batch_packaging/models/sale_order_line.py +++ b/nfu_sale_order_batch_packaging/models/sale_order_line.py @@ -13,7 +13,7 @@ class SaleOrderLine(models.Model): @api.constrains("product_uom_qty", "product_uom_max_qty") def _check_product_uom_qty(self): for order_line in self: - if order_line.product_uom_max_qty != 0 and order_line.product_uom_qty > order_line.product_uom_max_qty: + if order_line.product_uom_qty > order_line.product_uom_max_qty: raise UserError( _( f"{order_line.order_id.name},{order_line.product_id.name}:" @@ -24,6 +24,9 @@ class SaleOrderLine(models.Model): @api.model_create_multi def create(self, vals_list): for vals in vals_list: + if not vals.get("product_uom_max_qty") or vals.get("product_uom_max_qty") == 0: + product_qty = vals.get("product_uom_qty") + vals["product_uom_max_qty"] = product_qty if vals.get("product_id") and not vals.get("product_packaging_id"): product_id = vals.get("product_id") packaging = self.env["product.packaging"].search([("product_id", "=", product_id)], limit=1) diff --git a/nfu_sale_order_batch_packaging/readme/HISTORY.rst b/nfu_sale_order_batch_packaging/readme/HISTORY.rst index 3cc920c..baaf472 100644 --- a/nfu_sale_order_batch_packaging/readme/HISTORY.rst +++ b/nfu_sale_order_batch_packaging/readme/HISTORY.rst @@ -6,4 +6,8 @@ :1.3.0: add packaging states :1.3.1: add open_max_qty :1.3.2: fix color indicator -:1.3.3: Enable packagings on installation \ No newline at end of file +:1.3.3: Enable packagings on installation +:1.3.4: + - on creation set max_qty to product_uom_qty if not set + - remove zero exception for max_qty + - store open_packaging_qty on batch product module to make it sortable \ 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 0cf856e..4dbcf2b 100644 --- a/nfu_sale_order_batch_packaging/static/description/index.html +++ b/nfu_sale_order_batch_packaging/static/description/index.html @@ -391,23 +391,39 @@ and adds a packaging default to sale order batch.

-0.0.1:Initial module. +0.0.1:

Initial module.

+ -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 +1.2.1:

refactoring

+ -1.3.0:add packaging states +1.3.0:

add packaging states

+ -1.3.1:add open_max_qty +1.3.1:

add open_max_qty

+ -1.3.2:fix color indicator +1.3.2:

fix color indicator

+ -1.3.3:Enable packagings on installation +1.3.3:

Enable packagings on installation

+ + +1.3.4: + diff --git a/sale_order_batch/models/sale_order_batch_product.py b/sale_order_batch/models/sale_order_batch_product.py index 6bb4911..288634b 100644 --- a/sale_order_batch/models/sale_order_batch_product.py +++ b/sale_order_batch/models/sale_order_batch_product.py @@ -53,7 +53,7 @@ class SaleOrderBatchProduct(models.Model): def _compute_product_packaging_id(self): for line in self: # remove packaging if not match the product - if line.product_packaging_id.product_id != line.product_id: + if line.product_packaging_id and line.product_packaging_id.product_id != line.product_id: line.product_packaging_id = False # suggest always the first packaging if line.product_id and line.product_uom_qty and line.product_uom: