Skip to content

Commit

Permalink
[IMP] product_export_wamas: Support export product packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
duongtq committed Jan 3, 2024
1 parent 9a9b572 commit 552dff6
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 6 deletions.
4 changes: 2 additions & 2 deletions product_export_wamas/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion product_export_wamas/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions product_export_wamas/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import product_product
from . import product_packaging
26 changes: 26 additions & 0 deletions product_export_wamas/models/product_packaging.py
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)
2 changes: 1 addition & 1 deletion product_export_wamas/readme/DESCRIPTION.rst
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.
4 changes: 2 additions & 2 deletions product_export_wamas/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,10 @@ <h1 class="title">Product Export WAMAS</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0d40322d7af87b90b91e45d086147e47460bb9324d29b8f44dbd04dde45b361a
!! source digest: sha256:5b96cd5c14ab277f381c9421fc868d581985803feffd132325b7a0eea681496a
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/edi/tree/16.0/product_export_wamas"><img alt="OCA/edi" src="https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/edi-16-0/edi-16-0-product_export_wamas"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/edi&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module provide method to export product data as WAMAS format.</p>
<p>This module provides a method to export products and product packagings as WAMAS format.</p>
<div class="admonition important">
<p class="first admonition-title">Important</p>
<p class="last">This is an alpha version, the data model and design can change at any time without warning.
Expand Down
1 change: 1 addition & 0 deletions product_export_wamas/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import test_export_product
from . import test_export_packaging
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ODOO WAMAS 00000120231221041251ARTE00051000 00000000000000000000000 000000000001000000 000000000000000000000000 000000006000000000000000N1000000000000000N N
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ODOO WAMAS 00000120231221041251ARTE00051000113 113 113 00000000000000000000000 000000000001000000 000000000000000000000000 000000006000000000000000N1000000000000000N N
72 changes: 72 additions & 0 deletions product_export_wamas/tests/test_export_packaging.py
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)

0 comments on commit 552dff6

Please sign in to comment.