From 7a7409d4e7948795fca82ed26a8ef6ada5a5a159 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20G=C3=B6ttsch?=
Date: Tue, 25 Mar 2025 22:14:24 +0100
Subject: [PATCH] [imp] nfu_sale_order_batch_packaging: Add packaging states
---
nfu_sale_order_batch_packaging/README.rst | 1 +
.../__manifest__.py | 2 +-
.../models/sale_order_batch_product.py | 26 ++++++++++---------
.../readme/HISTORY.rst | 3 ++-
.../static/description/index.html | 2 ++
.../views/sale_order_batch_product_views.xml | 3 ++-
6 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/nfu_sale_order_batch_packaging/README.rst b/nfu_sale_order_batch_packaging/README.rst
index ad0dc1f..0c737d9 100644
--- a/nfu_sale_order_batch_packaging/README.rst
+++ b/nfu_sale_order_batch_packaging/README.rst
@@ -38,6 +38,7 @@ Changelog
:1.1.0: Live
:1.2.0: Add regeneration action for batch products
:1.2.1: refactoring
+:1.3.0: add packagin states
Bug Tracker
===========
diff --git a/nfu_sale_order_batch_packaging/__manifest__.py b/nfu_sale_order_batch_packaging/__manifest__.py
index c127d49..7578142 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.2.1",
+ "version": "16.0.1.3.0",
"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 9cfd405..ceed397 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
@@ -9,7 +9,7 @@ class SaleOrderBatchProduct(models.Model):
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_state = fields.Selection(selection=PACKAGING_STATES, compute="_compute_open_packagin_state")
@api.depends("sale_order_line_ids.product_uom_max_qty")
def _compute_product_uom_max_qty(self):
@@ -19,25 +19,27 @@ class SaleOrderBatchProduct(models.Model):
else:
product.product_uom_max_qty = False
- @api.depends("sale_order_line_ids.product_uom_qty")
+ @api.depends("product_uom_qty")
def _compute_open_packagin_qty(self):
for product in self:
open_packaging_qty = product.product_packaging_qty - (
- sum(product.sale_order_line_ids.mapped("product_uom_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
)
- # @api.depends("open_packaging_qty", "product_packaging_qty")
- # def _compute_open_packagin_state(self):
- # for product in self:
- # if product.open_packaging_qty == 0:
- # product.open_packaging_state = "full"
- # elif product.open_packaging_qty < product.product_packaging_qty:
- # product.open_packaging_state = "open"
- # else:
- # product.open_packaging_state = "last_open"
+ @api.depends("open_packaging_qty")
+ def _compute_open_packagin_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:
+ product.open_packaging_state = "full"
+ elif product.product_uom_qty < product.product_packaging_qty:
+ product.open_packaging_state = "open"
+ else:
+ product.open_packaging_state = "last_open"
@api.model_create_multi
def create(self, vals_list):
diff --git a/nfu_sale_order_batch_packaging/readme/HISTORY.rst b/nfu_sale_order_batch_packaging/readme/HISTORY.rst
index 0c83ee9..9a4e888 100644
--- a/nfu_sale_order_batch_packaging/readme/HISTORY.rst
+++ b/nfu_sale_order_batch_packaging/readme/HISTORY.rst
@@ -2,4 +2,5 @@
:1.0.0: rename to nfu_sale_order_batch_packaging
:1.1.0: Live
:1.2.0: Add regeneration action for batch products
-:1.2.1: refactoring
\ No newline at end of file
+:1.2.1: refactoring
+:1.3.0: add packagin states
\ 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 cd5df09..5b169be 100644
--- a/nfu_sale_order_batch_packaging/static/description/index.html
+++ b/nfu_sale_order_batch_packaging/static/description/index.html
@@ -401,6 +401,8 @@ and adds a packaging default to sale order batch.
| 1.2.1: | refactoring |
+| 1.3.0: | add packagin states |
+
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 acac722..e8d7563 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,8 @@
-
+
+