From 8ff7ea80e82a32f13d10b61ad5c5bf635e69d75e Mon Sep 17 00:00:00 2001
From: Quoc Duong
Date: Thu, 26 Sep 2024 10:50:19 +0700
Subject: [PATCH] [MIG] stock_packaging_calculator: Migration to 18.0
---
stock_packaging_calculator/README.rst | 17 +++++++++-----
stock_packaging_calculator/__manifest__.py | 2 +-
stock_packaging_calculator/models/product.py | 22 ++++++++++++++-----
.../readme/CONTRIBUTORS.md | 1 +
stock_packaging_calculator/readme/CREDITS.md | 1 +
.../static/description/index.html | 17 +++++++++-----
6 files changed, 43 insertions(+), 17 deletions(-)
create mode 100644 stock_packaging_calculator/readme/CREDITS.md
diff --git a/stock_packaging_calculator/README.rst b/stock_packaging_calculator/README.rst
index a54c236fdd1c..1c3052680d01 100644
--- a/stock_packaging_calculator/README.rst
+++ b/stock_packaging_calculator/README.rst
@@ -17,13 +17,13 @@ Stock packaging calculator
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github
- :target: https://github.com/OCA/stock-logistics-warehouse/tree/17.0/stock_packaging_calculator
+ :target: https://github.com/OCA/stock-logistics-warehouse/tree/18.0/stock_packaging_calculator
:alt: OCA/stock-logistics-warehouse
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
- :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-17-0/stock-logistics-warehouse-17-0-stock_packaging_calculator
+ :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-18-0/stock-logistics-warehouse-18-0-stock_packaging_calculator
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
- :target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&target_branch=17.0
+ :target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&target_branch=18.0
:alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -88,7 +88,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues `_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
-`feedback `_.
+`feedback `_.
Do not contact contributors directly about support or help with technical issues.
@@ -106,6 +106,13 @@ Contributors
- Simone Orsi
- Christopher Ormaza
- Nguyen Minh Chien
+- Tran Quoc Duong
+
+Other credits
+-------------
+
+The migration of this module from 17.0 to 18.0 was financially supported
+by Camptocamp.
Maintainers
-----------
@@ -120,6 +127,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
-This module is part of the `OCA/stock-logistics-warehouse `_ project on GitHub.
+This module is part of the `OCA/stock-logistics-warehouse `_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/stock_packaging_calculator/__manifest__.py b/stock_packaging_calculator/__manifest__.py
index 95d66c9b3d9d..d2acca7961da 100644
--- a/stock_packaging_calculator/__manifest__.py
+++ b/stock_packaging_calculator/__manifest__.py
@@ -3,7 +3,7 @@
{
"name": "Stock packaging calculator",
"summary": "Compute product quantity to pick by packaging",
- "version": "17.0.1.0.0",
+ "version": "18.0.1.0.0",
"development_status": "Beta",
"category": "Warehouse Management",
"website": "https://github.com/OCA/stock-logistics-warehouse",
diff --git a/stock_packaging_calculator/models/product.py b/stock_packaging_calculator/models/product.py
index febc26ea98a7..b7cdb7157831 100644
--- a/stock_packaging_calculator/models/product.py
+++ b/stock_packaging_calculator/models/product.py
@@ -113,20 +113,30 @@ def _product_qty_by_packaging(self, pkg_by_qty, qty, with_contained=False):
prepare_values = self.env.context.get(
"_packaging_values_handler", self._prepare_qty_by_packaging_values
)
+ uom_rounding = self.uom_id.rounding
for pkg in pkg_by_qty:
# Boost perf: no need to deduce the qty_per_pkg if the pkg_qty is 1
- if float_compare(pkg.qty, 1, precision_digits=self.uom_id.rounding) == 0:
- qty_per_pkg = int(qty)
- qty = 0.0
+ if float_compare(pkg.qty, 1, precision_rounding=uom_rounding) == 0:
+ # If qty is an integer, use int value, else round it
+ qty_diff = float_compare(
+ qty - int(qty), 0.0, precision_rounding=uom_rounding
+ )
+ qty_per_pkg = (
+ int(qty)
+ if qty_diff == 0
+ else float_round(qty, precision_rounding=uom_rounding)
+ )
+ qty = 0
else:
qty_per_pkg, qty = self._qty_by_pkg(pkg.qty, qty)
+
# To handle fractional quantities (eg: 0.5 Kg)
if pkg.is_unit and not float_is_zero(
- qty, precision_rounding=self.uom_id.rounding
+ qty, precision_rounding=uom_rounding
):
# `is_unit` package always be the last package by the sorting
# it has the same uom with the product, just sum the quantity
- qty_per_pkg += float_round(qty, precision_rounding=self.uom_id.rounding)
+ qty_per_pkg += float_round(qty, precision_rounding=uom_rounding)
qty = 0
if qty_per_pkg:
@@ -147,7 +157,7 @@ def _qty_by_pkg(self, pkg_qty, qty):
"""Calculate qty needed for given package qty."""
qty_per_pkg = 0
while (
- float_compare(qty - pkg_qty, 0.0, precision_digits=self.uom_id.rounding)
+ float_compare(qty - pkg_qty, 0.0, precision_rounding=self.uom_id.rounding)
>= 0.0
):
qty -= pkg_qty
diff --git a/stock_packaging_calculator/readme/CONTRIBUTORS.md b/stock_packaging_calculator/readme/CONTRIBUTORS.md
index d17ea290fea1..4944a9f34b2f 100644
--- a/stock_packaging_calculator/readme/CONTRIBUTORS.md
+++ b/stock_packaging_calculator/readme/CONTRIBUTORS.md
@@ -1,3 +1,4 @@
- Simone Orsi \<\>
- Christopher Ormaza \<\>
- Nguyen Minh Chien \<\>
+- Tran Quoc Duong \<\>
diff --git a/stock_packaging_calculator/readme/CREDITS.md b/stock_packaging_calculator/readme/CREDITS.md
new file mode 100644
index 000000000000..83b3ec91f7d5
--- /dev/null
+++ b/stock_packaging_calculator/readme/CREDITS.md
@@ -0,0 +1 @@
+The migration of this module from 17.0 to 18.0 was financially supported by Camptocamp.
diff --git a/stock_packaging_calculator/static/description/index.html b/stock_packaging_calculator/static/description/index.html
index fa9718bfafed..ca246e2eea3a 100644
--- a/stock_packaging_calculator/static/description/index.html
+++ b/stock_packaging_calculator/static/description/index.html
@@ -369,7 +369,7 @@ Stock packaging calculator
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:355bc67eed8ca907e517b4a8f46ac6b8a8e685664f2342d6d12fa7fc79a05b38
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-
+
Basic module providing an helper method to calculate the quantity of
product by packaging.
Table of contents
@@ -381,7 +381,8 @@ Stock packaging calculator
Credits
@@ -433,7 +434,7 @@
Bugs are tracked on GitHub Issues.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
-feedback.
+feedback.
Do not contact contributors directly about support or help with technical issues.
+
+
+
The migration of this module from 17.0 to 18.0 was financially supported
+by Camptocamp.
+