Skip to content

Commit

Permalink
[BPRT] base_edifact: Backport from 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
thienvh332 committed Sep 30, 2024
1 parent 70ddacf commit c9eafab
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion base_edifact/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 14 additions & 6 deletions base_edifact/models/edifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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,
Expand Down Expand Up @@ -273,7 +280,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.
Expand Down
1 change: 1 addition & 0 deletions base_edifact/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
* Marc Poch <[email protected]>
* Duong (Tran Quoc) <[email protected]>
* Tris Doan <[email protected]>
* Thien (Vo Hong) <[email protected]>
23 changes: 13 additions & 10 deletions base_edifact/tests/test_base_edifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,35 @@ 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):
"""Address segment
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)
Expand Down

0 comments on commit c9eafab

Please sign in to comment.