Skip to content

Commit eb82866

Browse files
duongtqOCA-git-bot
authored andcommitted
[IMP] sell_only_by_packaging: support negative rounding when converting packaging qty
1 parent 8a3cda1 commit eb82866

File tree

4 files changed

+51
-7
lines changed

4 files changed

+51
-7
lines changed

sell_only_by_packaging/README.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ sale orders.
3434
The creation/update of sale order line will be blocked (by constraints) if the data on the
3535
sale.order.line does not fit with the configuration of the product's packagings.
3636

37-
It's also possible to force the quantity to sell during creation/modification of the sale order line
37+
It's also possible to force the quantity to sell/return during creation/modification of the sale order line
3838
if the "Force sale quantity" is ticked on the packaging and the "Sell only by packaging" is ticked on product.
3939

40-
For example, if your packaging is set to sell by 5 units and the employee fill
41-
the quantity with 3, the quantity will be automatically replaced by 5 (it always rounds up).
40+
For example,
41+
- To sell packaging (fill positive product quantities), if your packaging is set to sell by 5 units and the employee fill
42+
the quantity with 3, the quantity will be automatically replaced by 5 (it always rounds up to the nearest multiple of the packaging quantity).
43+
44+
- To return packaging (fill negative product quantities), if your packaging is set with -5 units and the employee fill
45+
the quantity with -3, the quantity will be automatically replaced by -5 (it always rounds down to the nearest multiple of the packaging quantity).
4246

4347
.. IMPORTANT::
4448
This is an alpha version, the data model and design can change at any time without warning.

sell_only_by_packaging/models/product_product.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,16 @@ def _convert_packaging_qty(self, qty, uom, packaging):
5656
)
5757
!= 0
5858
):
59-
qty = qty - (qty % q) + q
59+
forced_qty = qty - (qty % q) + q
60+
# Support negative rounding
61+
if (
62+
float_compare(
63+
qty,
64+
0.0,
65+
precision_rounding=0.001,
66+
)
67+
< 0
68+
):
69+
forced_qty -= q
70+
return forced_qty
6071
return qty

sell_only_by_packaging/readme/DESCRIPTION.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ sale orders.
44
The creation/update of sale order line will be blocked (by constraints) if the data on the
55
sale.order.line does not fit with the configuration of the product's packagings.
66

7-
It's also possible to force the quantity to sell during creation/modification of the sale order line
7+
It's also possible to force the quantity to sell/return during creation/modification of the sale order line
88
if the "Force sale quantity" is ticked on the packaging and the "Sell only by packaging" is ticked on product.
99

10-
For example, if your packaging is set to sell by 5 units and the employee fill
11-
the quantity with 3, the quantity will be automatically replaced by 5 (it always rounds up).
10+
For example,
11+
- To sell packaging (fill positive product quantities), if your packaging is set to sell by 5 units and the employee fill
12+
the quantity with 3, the quantity will be automatically replaced by 5 (it always rounds up to the nearest multiple of the packaging quantity).
13+
14+
- To return packaging (fill negative product quantities), if your packaging is set with -5 units and the employee fill
15+
the quantity with -3, the quantity will be automatically replaced by -5 (it always rounds down to the nearest multiple of the packaging quantity).

sell_only_by_packaging/tests/test_sale_only_by_packaging.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,31 @@ def test_convert_packaging_qty(self):
8989
self.assertAlmostEqual(
9090
so_line.product_uom_qty, 220, places=self.precision
9191
)
92+
# Check with negative quantity
93+
so_line.product_uom_qty = -52
94+
self.assertAlmostEqual(
95+
so_line.product_uom_qty, -60, places=self.precision
96+
)
97+
so_line.product_uom_qty = -40
98+
self.assertAlmostEqual(
99+
so_line.product_uom_qty, -40, places=self.precision
100+
)
101+
so_line.product_uom_qty = -38
102+
self.assertAlmostEqual(
103+
so_line.product_uom_qty, -40, places=self.precision
104+
)
105+
so_line.product_uom_qty = -22
106+
self.assertAlmostEqual(
107+
so_line.product_uom_qty, -40, places=self.precision
108+
)
109+
so_line.product_uom_qty = -72
110+
self.assertAlmostEqual(
111+
so_line.product_uom_qty, -80, places=self.precision
112+
)
113+
so_line.product_uom_qty = -209.98
114+
self.assertAlmostEqual(
115+
so_line.product_uom_qty, -220, places=self.precision
116+
)
92117

93118
def test_onchange_qty_is_not_pack_multiple(self):
94119
"""Check package when qantity is not a multiple of package quantity.

0 commit comments

Comments
 (0)