From 8c8091b4fd9fd6fab94d9be6c724395535c6c652 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20G=C3=B6ttsch?=
Date: Fri, 9 May 2025 23:21:09 +0200
Subject: [PATCH] [IMP] nfu_sale_order_batch: always adjust max_qty to be at
least uom_qty
---
nfu_sale_order_batch_packaging/README.rst | 1 +
.../models/sale_order_line.py | 11 +++++++++++
nfu_sale_order_batch_packaging/readme/HISTORY.rst | 3 ++-
.../static/description/index.html | 1 +
4 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/nfu_sale_order_batch_packaging/README.rst b/nfu_sale_order_batch_packaging/README.rst
index fd34d1f..efc3ba3 100644
--- a/nfu_sale_order_batch_packaging/README.rst
+++ b/nfu_sale_order_batch_packaging/README.rst
@@ -46,6 +46,7 @@ Changelog
- 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
+ - always adjust max_qty to be at least uom_qty except you only set max qty
Bug Tracker
===========
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 4c6bc90..2ca3586 100644
--- a/nfu_sale_order_batch_packaging/models/sale_order_line.py
+++ b/nfu_sale_order_batch_packaging/models/sale_order_line.py
@@ -32,3 +32,14 @@ class SaleOrderLine(models.Model):
packaging = self.env["product.packaging"].search([("product_id", "=", product_id)], limit=1)
vals["product_packaging_id"] = packaging.id
return super().create(vals_list)
+
+ def write(self, vals):
+ product_qty = vals.get("product_uom_qty")
+ product_max_qty = vals.get("product_uom_max_qty")
+ if product_qty and product_max_qty and product_qty > product_max_qty:
+ vals["product_uom_max_qty"] = product_qty
+ elif product_qty:
+ for line in self:
+ if product_qty > line.product_uom_max_qty:
+ line["product_uom_max_qty"] = product_qty
+ return super().write(vals)
diff --git a/nfu_sale_order_batch_packaging/readme/HISTORY.rst b/nfu_sale_order_batch_packaging/readme/HISTORY.rst
index baaf472..0a08805 100644
--- a/nfu_sale_order_batch_packaging/readme/HISTORY.rst
+++ b/nfu_sale_order_batch_packaging/readme/HISTORY.rst
@@ -10,4 +10,5 @@
: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
+ - store open_packaging_qty on batch product module to make it sortable
+ - always adjust max_qty to be at least uom_qty except you only set 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 4dbcf2b..8113560 100644
--- a/nfu_sale_order_batch_packaging/static/description/index.html
+++ b/nfu_sale_order_batch_packaging/static/description/index.html
@@ -422,6 +422,7 @@ and adds a packaging default to sale order batch.
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
+always adjust max_qty to be at least uom_qty except you only set max qty