From 5def864b2c1880b078d351b3bc1dbff0fb3fa9e1 Mon Sep 17 00:00:00 2001 From: thien Date: Mon, 22 Apr 2024 10:13:51 +0700 Subject: [PATCH] [BPRT] base_edifact: Backport from 16.0 --- base_edifact/__manifest__.py | 2 +- base_edifact/models/edifact.py | 20 ++++++++++++++------ base_edifact/readme/CONTRIBUTORS.rst | 1 + base_edifact/tests/test_base_edifact.py | 23 +++++++++++++---------- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/base_edifact/__manifest__.py b/base_edifact/__manifest__.py index 254ab8dca8a..b81e931daa8 100644 --- a/base_edifact/__manifest__.py +++ b/base_edifact/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Base EDIFACT", "summary": "UN/EDIFACT/D96A utilities using pydifact parser", - "version": "16.0.1.3.0", + "version": "12.0.1.0.0", "development_status": "Alpha", "category": "Tools", "website": "https://github.com/OCA/edi", diff --git a/base_edifact/models/edifact.py b/base_edifact/models/edifact.py index c8d63823752..20f7d60304d 100644 --- a/base_edifact/models/edifact.py +++ b/base_edifact/models/edifact.py @@ -109,7 +109,9 @@ def map2odoo_partner(self, seg): codes = ["BY", "SU"] reference_code = seg[0] if reference_code not in codes: - raise NotImplementedError(f"Code '{reference_code}' not implemented") + raise NotImplementedError( + "Code '{}' not implemented".format(reference_code) + ) # party_identification = seg[1] party_id = party_identification[0] @@ -124,7 +126,8 @@ def map2odoo_address(self, seg): DP. Party to which goods should be delivered, if not identical with consignee. NAD+DP+5550534000086::9+++++++DE' - NAD segment: ['DP', ['5550534022101', '', '9'], '', '', '', '', '', '', 'ES'] + NAD segment: + ['DP', ['5550534022101', '', '9'], '', '', '', '', '', '', 'ES'] IV. Party to whom an invoice is issued. NAD+IV+5450534005838::9++AMAZON EU SARL:NIEDERLASSUNG DEUTSCHLAND+MARCEL-BREUER-STR. 12+MUENCHEN++80807+DE @@ -158,9 +161,12 @@ def map2odoo_address(self, seg): if lenght_seg > 2 and bool(seg[2]): d["name"] = seg[2] if lenght_seg > 3 and bool(seg[3]): - d["name"] = "{}{}".format(f"{d['name']}. " if d.get("name") else "", seg[3]) + d["name"] = "{}{}".format( + "{}. ".format(d["name"]) if d.get("name") else "", seg[3] + ) if lenght_seg > 4 and bool(seg[4]): - # Street address and/or PO Box number in a structured address: one to three lines. + # Street address and/or PO Box number in a structured address: + # one to three lines. d["street"] = seg[4] if lenght_seg > 5 and bool(seg[5]): d["city"] = seg[5] @@ -180,7 +186,8 @@ def map2odoo_currency(self, seg): """ ['2', 'EUR', '9'] """ - # Identification of the name or symbol of the monetary unit involved in the transaction. + # Identification of the name or symbol of the monetary unit involved + # in the transaction. currency_coded = seg[1] return { "iso": currency_coded, @@ -279,7 +286,8 @@ def create_interchange(self, sender, recipient, control_ref, syntax_identifier): - 14: EAN (European Article Numbering Association) :param list recipient: Identification of the recipient of the interchange. example: ["40411", "14"] - :param str control_ref: Unique reference assigned by the sender to an interchange. + :param str control_ref: + Unique reference assigned by the sender to an interchange. example: "10" :param list syntax_identifier: Identification of the agency controlling the syntax and indication of syntax level, plus the syntax version number. diff --git a/base_edifact/readme/CONTRIBUTORS.rst b/base_edifact/readme/CONTRIBUTORS.rst index a7a744310a1..2bb9a7005fe 100644 --- a/base_edifact/readme/CONTRIBUTORS.rst +++ b/base_edifact/readme/CONTRIBUTORS.rst @@ -1,3 +1,4 @@ * Rafa Morant (www.albasoft.com) * Marc Poch * Duong (Tran Quoc) +* Thien (Vo Hong) diff --git a/base_edifact/tests/test_base_edifact.py b/base_edifact/tests/test_base_edifact.py index 0189cfb2888..cfae46a97a7 100644 --- a/base_edifact/tests/test_base_edifact.py +++ b/base_edifact/tests/test_base_edifact.py @@ -13,24 +13,26 @@ def _get_file_content(filename): class TestBaseEdifact(TransactionCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.base_edifact_model = cls.env["base.edifact"] - cls.product = cls.env.ref("product.product_product_1") - cls.product.barcode = "9783898" - cls.product.default_code = "12767" + + def setUp(self): + super(TestBaseEdifact, self).setUp() + self.base_edifact_model = self.env["base.edifact"] + self.product = self.env.ref("product.product_product_1") + self.product.barcode = "9783898" + self.product.default_code = "12767" def test_pydifact_obj(self): edifact_docu = _get_file_content("Retail_EDIFACT_ORDERS_sample1.txt") obj = self.base_edifact_model.pydifact_obj(edifact_docu) - # [1]: to get the list messages, [0]: to get the first list value of the segments + # [1]: to get the list messages + # [0]: to get the first list value of the segments self.assertEqual(obj[1]["segments"][0]["BGM"][1], "1AA1TEST") def test_pydifact_obj_latin1(self): edifact_docu = _get_file_content("test_orders_-_no_ean_in_LIN_segments.txt") obj = self.base_edifact_model.pydifact_obj(edifact_docu) - # [1]: to get the list messages, [3]: to get the third list value of the segments + # [1]: to get the list messages + # [3]: to get the third list value of the segments self.assertEqual(obj[1]["segments"][3]["NAD"][3], "SuppliƩr1") def test_map2odoo_address(self): @@ -38,7 +40,8 @@ def test_map2odoo_address(self): DP. Party to which goods should be delivered, if not identical with consignee. NAD+DP+5550534000086::9+++++++DE' - NAD segment: ['DP', ['5550534022101', '', '9'], '', '', '', '', '', '', 'ES'] + NAD segment: + ['DP', ['5550534022101', '', '9'], '', '', '', '', '', '', 'ES'] """ seg = ["DP", ["5550534000086", "", "9"], "", "", "", "", "", "", "ES"] address = self.base_edifact_model.map2odoo_address(seg)