From bcedb0b8974a56c321f1570f62231b104d571b4e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20G=C3=B6ttsch?=
Date: Wed, 18 Jun 2025 22:40:10 +0200
Subject: [PATCH] [FIX] nfu_sale_order_batch_packaging: store all quantities
and round open values
---
nfu_sale_order_batch_packaging/README.rst | 1 +
nfu_sale_order_batch_packaging/__manifest__.py | 2 +-
.../models/sale_order_batch_product.py | 18 ++++++++++--------
.../readme/HISTORY.rst | 3 ++-
.../static/description/index.html | 5 ++++-
.../views/sale_order_batch_product_views.xml | 6 +++---
6 files changed, 21 insertions(+), 14 deletions(-)
diff --git a/nfu_sale_order_batch_packaging/README.rst b/nfu_sale_order_batch_packaging/README.rst
index efc3ba3..9698cf1 100644
--- a/nfu_sale_order_batch_packaging/README.rst
+++ b/nfu_sale_order_batch_packaging/README.rst
@@ -47,6 +47,7 @@ Changelog
- 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
+:1.3.4: store all quantities and round open values
Bug Tracker
===========
diff --git a/nfu_sale_order_batch_packaging/__manifest__.py b/nfu_sale_order_batch_packaging/__manifest__.py
index 09352c6..f805b54 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.4",
+ "version": "16.0.1.3.5",
"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 53c4c03..fbd2660 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
@@ -7,9 +7,11 @@ PACKAGING_STATES = [("open", "Open"), ("full", "Full"), ("last_open", "Last pack
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", store=True)
- open_packaging_max_qty = fields.Float(compute="_compute_open_packaging_max_qty")
+ product_uom_max_qty = fields.Float(
+ "Max Qty", compute="_compute_product_uom_max_qty", precompute=True, store=True, digits=[12, 3]
+ )
+ open_packaging_qty = fields.Float(compute="_compute_open_packaging_qty", store=True, digits=[12, 3])
+ open_packaging_max_qty = fields.Float(compute="_compute_open_packaging_max_qty", store=True, digits=[12, 3])
open_packaging_state = fields.Selection(selection=PACKAGING_STATES, compute="_compute_open_packaging_state")
@api.depends("sale_order_line_ids.product_uom_max_qty")
@@ -21,11 +23,11 @@ class SaleOrderBatchProduct(models.Model):
def _compute_open_packaging_qty(self):
for product in self:
if product.product_packaging_id:
- open_packaging_qty = product.product_packaging_qty - (
- product.product_uom_qty % product.product_packaging_qty
+ open_packaging_qty = product.product_packaging_qty - round(
+ product.product_uom_qty % product.product_packaging_qty, 3
)
product.open_packaging_qty = (
- 0 if open_packaging_qty == product.product_packaging_qty else open_packaging_qty
+ 0.0 if open_packaging_qty == product.product_packaging_qty else open_packaging_qty
)
else:
product.open_packaging_qty = 0.0
@@ -35,8 +37,8 @@ class SaleOrderBatchProduct(models.Model):
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
+ product.open_packaging_max_qty = product.product_packaging_qty - round(
+ product.product_uom_max_qty % product.product_packaging_qty, 3
)
else:
product.open_packaging_max_qty = 0.0
diff --git a/nfu_sale_order_batch_packaging/readme/HISTORY.rst b/nfu_sale_order_batch_packaging/readme/HISTORY.rst
index 0a08805..815e4d9 100644
--- a/nfu_sale_order_batch_packaging/readme/HISTORY.rst
+++ b/nfu_sale_order_batch_packaging/readme/HISTORY.rst
@@ -11,4 +11,5 @@
- 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
\ No newline at end of file
+ - always adjust max_qty to be at least uom_qty except you only set max qty
+:1.3.4: store all quantities and round open values
\ 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 8113560..d5627f4 100644
--- a/nfu_sale_order_batch_packaging/static/description/index.html
+++ b/nfu_sale_order_batch_packaging/static/description/index.html
@@ -418,7 +418,7 @@ and adds a packaging default to sale order batch.
| 1.3.3: | Enable packagings on installation
|
-| 1.3.4: |
+| 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
@@ -426,6 +426,9 @@ and adds a packaging default to sale order batch.
|
+| 1.3.4: | store all quantities and round open values
+ |
+
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 7624a11..3f01f0f 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
@@ -9,10 +9,10 @@
-
+
|
|---|