Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] sell_only_by_packaging: support negative rounding when converting packaging qty #3248

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions sell_only_by_packaging/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ sale orders.
The creation/update of sale order line will be blocked (by constraints) if the data on the
sale.order.line does not fit with the configuration of the product's packagings.

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

For example, if your packaging is set to sell by 5 units and the employee fill
the quantity with 3, the quantity will be automatically replaced by 5 (it always rounds up).
For example,
- To sell packaging (fill positive product quantities), if your packaging is set to sell by 5 units and the employee fill
the quantity with 3, the quantity will be automatically replaced by 5 (it always rounds up to the nearest multiple of the packaging quantity).

- To return packaging (fill negative product quantities), if your packaging is set with -5 units and the employee fill
the quantity with -3, the quantity will be automatically replaced by -5 (it always rounds down to the nearest multiple of the packaging quantity).

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Expand Down
15 changes: 13 additions & 2 deletions sell_only_by_packaging/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,20 @@ def _convert_packaging_qty(self, qty, uom, packaging):
and float_compare(
qty / q,
float_round(qty / q, precision_rounding=1.0),
precision_rounding=0.001,
precision_rounding=uom.rounding,
)
!= 0
):
qty = qty - (qty % q) + q
forced_qty = qty - (qty % q) + q
# Support negative rounding
if (
float_compare(
qty,
0.0,
precision_rounding=uom.rounding,
)
< 0
):
forced_qty -= q
return forced_qty
return qty
10 changes: 7 additions & 3 deletions sell_only_by_packaging/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ sale orders.
The creation/update of sale order line will be blocked (by constraints) if the data on the
sale.order.line does not fit with the configuration of the product's packagings.

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

For example, if your packaging is set to sell by 5 units and the employee fill
the quantity with 3, the quantity will be automatically replaced by 5 (it always rounds up).
For example,
- To sell packaging (fill positive product quantities), if your packaging is set to sell by 5 units and the employee fill
the quantity with 3, the quantity will be automatically replaced by 5 (it always rounds up to the nearest multiple of the packaging quantity).

- To return packaging (fill negative product quantities), if your packaging is set with -5 units and the employee fill
the quantity with -3, the quantity will be automatically replaced by -5 (it always rounds down to the nearest multiple of the packaging quantity).
25 changes: 25 additions & 0 deletions sell_only_by_packaging/tests/test_sale_only_by_packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,31 @@ def test_convert_packaging_qty(self):
self.assertAlmostEqual(
so_line.product_uom_qty, 220, places=self.precision
)
# Check with negative quantity
so_line.product_uom_qty = -52
self.assertAlmostEqual(
so_line.product_uom_qty, -60, places=self.precision
)
so_line.product_uom_qty = -40
self.assertAlmostEqual(
so_line.product_uom_qty, -40, places=self.precision
)
so_line.product_uom_qty = -38
self.assertAlmostEqual(
so_line.product_uom_qty, -40, places=self.precision
)
so_line.product_uom_qty = -22
self.assertAlmostEqual(
so_line.product_uom_qty, -40, places=self.precision
)
so_line.product_uom_qty = -72
self.assertAlmostEqual(
so_line.product_uom_qty, -80, places=self.precision
)
so_line.product_uom_qty = -209.98
self.assertAlmostEqual(
so_line.product_uom_qty, -220, places=self.precision
)

def test_onchange_qty_is_not_pack_multiple(self):
"""Check package when qantity is not a multiple of package quantity.
Expand Down
Loading