forked from OCA/stock-logistics-warehouse
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
s_packaging_calculator: add product_qty_by_packaging_as_str
Retrieve quickly packagin bty qty as a string.
- Loading branch information
Showing
5 changed files
with
153 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import test_packaging_calc | ||
from . import test_pkg_qty_str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright 2020 Camptocamp SA | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl) | ||
from odoo.tests import SavepointCase | ||
|
||
|
||
class TestCommon(SavepointCase): | ||
|
||
at_install = False | ||
post_install = True | ||
maxDiff = None | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) | ||
cls.uom_unit = cls.env.ref("uom.product_uom_unit") | ||
cls.product_a = cls.env["product.product"].create( | ||
{ | ||
"name": "Product A", | ||
"uom_id": cls.uom_unit.id, | ||
"uom_po_id": cls.uom_unit.id, | ||
} | ||
) | ||
cls.pkg_box = cls.env["product.packaging"].create( | ||
{"name": "Box", "product_id": cls.product_a.id, "qty": 50, "barcode": "BOX"} | ||
) | ||
cls.pkg_big_box = cls.env["product.packaging"].create( | ||
{ | ||
"name": "Big Box", | ||
"product_id": cls.product_a.id, | ||
"qty": 200, | ||
"barcode": "BIGBOX", | ||
} | ||
) | ||
cls.pkg_pallet = cls.env["product.packaging"].create( | ||
{ | ||
"name": "Pallet", | ||
"product_id": cls.product_a.id, | ||
"qty": 2000, | ||
"barcode": "PALLET", | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright 2021 Camptocamp SA | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl) | ||
from .common import TestCommon | ||
|
||
|
||
class TestAsStr(TestCommon): | ||
def test_as_str(self): | ||
self.assertEqual(self.product_a.product_qty_by_packaging_as_str(10), "") | ||
self.assertEqual(self.product_a.product_qty_by_packaging_as_str(100), "2 Box") | ||
self.assertEqual( | ||
self.product_a.product_qty_by_packaging_as_str(250), "1 Big Box,\xa01 Box" | ||
) | ||
self.assertEqual( | ||
self.product_a.product_qty_by_packaging_as_str(255), | ||
"1 Big Box,\xa01 Box,\xa05 Units", | ||
) | ||
|
||
def test_as_str_w_units(self): | ||
self.assertEqual( | ||
self.product_a.product_qty_by_packaging_as_str( | ||
10, include_total_units=True | ||
), | ||
"", | ||
) | ||
self.assertEqual( | ||
self.product_a.product_qty_by_packaging_as_str( | ||
100, include_total_units=True | ||
), | ||
"2 Box (100 Units)", | ||
) | ||
self.assertEqual( | ||
self.product_a.product_qty_by_packaging_as_str( | ||
250, include_total_units=True | ||
), | ||
"1 Big Box,\xa01 Box (250 Units)", | ||
) | ||
self.assertEqual( | ||
self.product_a.product_qty_by_packaging_as_str( | ||
255, include_total_units=True | ||
), | ||
"1 Big Box,\xa01 Box,\xa05 Units (255 Units)", | ||
) | ||
|
||
def test_as_str_custom_name(self): | ||
self.assertEqual( | ||
self.product_a.with_context( | ||
_qty_by_packaging_as_str=lambda pkg, qty: f"{pkg.name} {qty} FOO" | ||
).product_qty_by_packaging_as_str(250), | ||
"Big Box 1 FOO,\xa0Box 1 FOO", | ||
) |