-
-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] product_export_wamas: Support export product packaging
- Loading branch information
duongtq
committed
Jan 3, 2024
1 parent
9a9b572
commit 552dff6
Showing
10 changed files
with
110 additions
and
6 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
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 product_product | ||
from . import product_packaging |
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,26 @@ | ||
# Copyright 2024 Jacques-Etienne Baudoux (BCIM) <je@bcim.be> | ||
# Copyright 2024 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import _, models | ||
|
||
|
||
class ProductPackaging(models.Model): | ||
_inherit = "product.packaging" | ||
|
||
def _wamas_export(self, specific_dict=None, telegram_type=False): | ||
""" | ||
Export the packaging data as WAMAS format | ||
:return: packaging data as WAMAS format | ||
:rtype: bytes | ||
""" | ||
self.ensure_one() | ||
if not telegram_type: | ||
raise ValueError(_("Please define expected telegram type.")) | ||
# If having a specific dict for the packaging, we use it | ||
if specific_dict and isinstance(specific_dict, dict): | ||
dict_packaging = specific_dict | ||
else: | ||
dict_packaging = self.read()[0] | ||
return self.env["base.wamas.ubl"].dict2wamas(dict_packaging, telegram_type) |
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 @@ | ||
This module provide method to export product data as WAMAS format. | ||
This module provides a method to export products and product packagings as WAMAS format. |
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_export_product | ||
from . import test_export_packaging |
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 @@ | ||
ODOO WAMAS 00000120231221041251ARTE00051000 00000000000000000000000 000000000001000000 000000000000000000000000 000000006000000000000000N1000000000000000N N |
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 @@ | ||
ODOO WAMAS 00000120231221041251ARTE00051000113 113 113 00000000000000000000000 000000000001000000 000000000000000000000000 000000006000000000000000N1000000000000000N N |
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,72 @@ | ||
# Copyright 2024 Jacques-Etienne Baudoux (BCIM) <je@bcim.be> | ||
# Copyright 2024 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
|
||
from freezegun import freeze_time | ||
|
||
from odoo.tests import common | ||
from odoo.tools import file_open | ||
|
||
|
||
class TestExportPackaging(common.TransactionCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.product = cls.env["product.product"].create( | ||
{ | ||
"default_code": "113 113 113", | ||
"name": "The Yellow Chair", | ||
"detailed_type": "product", | ||
"weight": 2, | ||
"standard_price": 10, | ||
"lst_price": 12, | ||
"barcode": "555555", | ||
} | ||
) | ||
cls.packaging = cls.env["product.packaging"].create( | ||
{ | ||
"name": "Combo 6 Chair", | ||
"product_id": cls.product.id, | ||
"qty": 6, | ||
"barcode": "1231231", | ||
} | ||
) | ||
|
||
def test_export_without_telegram(self): | ||
with self.assertRaisesRegex( | ||
ValueError, "Please define expected telegram type." | ||
): | ||
self.product._wamas_export() | ||
|
||
@freeze_time("2023-12-21 04:12:51") | ||
def test_export_without_specific_dict(self): | ||
exported_data = self.packaging._wamas_export(telegram_type="ARTE") | ||
expected_data = ( | ||
file_open( | ||
"product_export_wamas/tests/samples/EXPECTED_PACKAGING_1.wamas", "r" | ||
) | ||
.read() | ||
.encode("iso-8859-1") | ||
) | ||
|
||
self.assertEqual(exported_data, expected_data) | ||
|
||
@freeze_time("2023-12-21 04:12:51") | ||
def test_export_with_specific_dict(self): | ||
specific_dict = { | ||
"name": "Combo 6 Chair", | ||
"product": self.product.default_code, | ||
"qty": 6, | ||
} | ||
exported_data = self.packaging._wamas_export( | ||
specific_dict=specific_dict, telegram_type="ARTE" | ||
) | ||
expected_data = ( | ||
file_open( | ||
"product_export_wamas/tests/samples/EXPECTED_PACKAGING_2.wamas", "r" | ||
) | ||
.read() | ||
.encode("iso-8859-1") | ||
) | ||
self.assertEqual(exported_data, expected_data) |