diff --git a/product_export_wamas/README.rst b/product_export_wamas/README.rst index e3f3380eee..448cd991ff 100644 --- a/product_export_wamas/README.rst +++ b/product_export_wamas/README.rst @@ -7,7 +7,7 @@ Product Export WAMAS !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:0d40322d7af87b90b91e45d086147e47460bb9324d29b8f44dbd04dde45b361a + !! source digest: sha256:5b96cd5c14ab277f381c9421fc868d581985803feffd132325b7a0eea681496a !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png @@ -28,7 +28,7 @@ Product Export WAMAS |badge1| |badge2| |badge3| |badge4| |badge5| -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. .. IMPORTANT:: This is an alpha version, the data model and design can change at any time without warning. diff --git a/product_export_wamas/__manifest__.py b/product_export_wamas/__manifest__.py index d0ef961f31..e566e0abda 100644 --- a/product_export_wamas/__manifest__.py +++ b/product_export_wamas/__manifest__.py @@ -4,7 +4,9 @@ { "name": "Product Export WAMAS", - "summary": """Module provides a method to export product as WAMAS format""", + "summary": """ + Module provides a method to export products and product packagings as WAMAS format + """, "version": "16.0.1.0.0", "development_status": "Alpha", "category": "Hidden", diff --git a/product_export_wamas/models/__init__.py b/product_export_wamas/models/__init__.py index 5c74c8c30f..a937af2848 100644 --- a/product_export_wamas/models/__init__.py +++ b/product_export_wamas/models/__init__.py @@ -1 +1,2 @@ from . import product_product +from . import product_packaging diff --git a/product_export_wamas/models/product_packaging.py b/product_export_wamas/models/product_packaging.py new file mode 100644 index 0000000000..705a936cb5 --- /dev/null +++ b/product_export_wamas/models/product_packaging.py @@ -0,0 +1,26 @@ +# Copyright 2024 Jacques-Etienne Baudoux (BCIM) +# 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) diff --git a/product_export_wamas/readme/DESCRIPTION.rst b/product_export_wamas/readme/DESCRIPTION.rst index 40cd7614ad..31262425b7 100644 --- a/product_export_wamas/readme/DESCRIPTION.rst +++ b/product_export_wamas/readme/DESCRIPTION.rst @@ -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. diff --git a/product_export_wamas/static/description/index.html b/product_export_wamas/static/description/index.html index 787be286c2..81d7123748 100644 --- a/product_export_wamas/static/description/index.html +++ b/product_export_wamas/static/description/index.html @@ -367,10 +367,10 @@

Product Export WAMAS

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:0d40322d7af87b90b91e45d086147e47460bb9324d29b8f44dbd04dde45b361a +!! source digest: sha256:5b96cd5c14ab277f381c9421fc868d581985803feffd132325b7a0eea681496a !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Alpha License: AGPL-3 OCA/edi Translate me on Weblate Try me on Runboat

-

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.

Important

This is an alpha version, the data model and design can change at any time without warning. diff --git a/product_export_wamas/tests/__init__.py b/product_export_wamas/tests/__init__.py index 7bf0052381..8de7fe3848 100644 --- a/product_export_wamas/tests/__init__.py +++ b/product_export_wamas/tests/__init__.py @@ -1 +1,2 @@ from . import test_export_product +from . import test_export_packaging diff --git a/product_export_wamas/tests/samples/EXPECTED_PACKAGING_1.wamas b/product_export_wamas/tests/samples/EXPECTED_PACKAGING_1.wamas new file mode 100644 index 0000000000..c81af3c069 --- /dev/null +++ b/product_export_wamas/tests/samples/EXPECTED_PACKAGING_1.wamas @@ -0,0 +1 @@ +ODOO WAMAS 00000120231221041251ARTE00051000 00000000000000000000000 000000000001000000 000000000000000000000000 000000006000000000000000N1000000000000000N N \ No newline at end of file diff --git a/product_export_wamas/tests/samples/EXPECTED_PACKAGING_2.wamas b/product_export_wamas/tests/samples/EXPECTED_PACKAGING_2.wamas new file mode 100644 index 0000000000..efc9163731 --- /dev/null +++ b/product_export_wamas/tests/samples/EXPECTED_PACKAGING_2.wamas @@ -0,0 +1 @@ +ODOO WAMAS 00000120231221041251ARTE00051000113 113 113 00000000000000000000000 000000000001000000 000000000000000000000000 000000006000000000000000N1000000000000000N N \ No newline at end of file diff --git a/product_export_wamas/tests/test_export_packaging.py b/product_export_wamas/tests/test_export_packaging.py new file mode 100644 index 0000000000..4afed8a853 --- /dev/null +++ b/product_export_wamas/tests/test_export_packaging.py @@ -0,0 +1,72 @@ +# Copyright 2024 Jacques-Etienne Baudoux (BCIM) +# 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)