Skip to content

Commit

Permalink
[IMP] base_edifact: Add unit test for test_map2odoo_description
Browse files Browse the repository at this point in the history
  • Loading branch information
thienvh332 committed Oct 24, 2023
1 parent c27655a commit 5926ca2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
13 changes: 7 additions & 6 deletions base_edifact/models/edifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ def pydifact_obj(self, docu):

@api.model
def _loads_edifact(self, order_file):
# TODO: use chardet library for get encoding
try:
interchange = Interchange.from_str(order_file.decode())
except UnicodeDecodeError:
interchange = Interchange.from_str(order_file.decode('latin-1'))
interchange = Interchange.from_str(order_file.decode("latin-1"))
return interchange

@api.model
Expand All @@ -87,7 +88,7 @@ def map2odoo_date(self, dt):
# '102'
date_format = "%Y%m%d%H%M%S"
length_dt = len(dt[1])
if (length_dt % 2 == 0 and length_dt in range(8, 13, 2)):
if length_dt % 2 == 0 and length_dt in range(8, 13, 2):
date_format = date_format[0 : length_dt - 2]
dtt = datetime.datetime.strptime(dt[1], date_format)
return dtt.date()
Expand Down Expand Up @@ -187,7 +188,7 @@ def map2odoo_currency(self, seg):
}

@api.model
def map2odoo_product(self, seg, pia = None):
def map2odoo_product(self, seg, pia=None):
"""
:seg: LIN segment
['1', '', ['8885583503464', 'EN']]
Expand All @@ -214,7 +215,7 @@ def map2odoo_qty(self, seg):
return float(seg[0][1])

@api.model
def map2odoo_unit_price(self, seg = None):
def map2odoo_unit_price(self, seg=None):
"""
'PRI' EDI segment: [['AAA', '19.75']]
Price qualifier:
Expand All @@ -229,7 +230,7 @@ def map2odoo_unit_price(self, seg = None):
if pri[0] == "AAB":
return float(pri[1])
return 0.0

@api.model
def map2odoo_description(self, seg):
"""
Expand All @@ -240,4 +241,4 @@ def map2odoo_description(self, seg):
if seg:
description = seg[2][3]
return description
return None
return None
2 changes: 1 addition & 1 deletion base_edifact/tests/files/test_orders_-_no_PRI_segments.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ QTY+21:1:24'
UNS+S'
CNT+2:3'
UNT+267+000011956901'
UNZ+1+2'
UNZ+1+2'
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ UNS+S'
MOA+125:247.98'
CNT+2:5'
UNT+67+3269'
UNZ+1+003274'
UNZ+1+003274'
11 changes: 8 additions & 3 deletions base_edifact/tests/test_base_edifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_pydifact_obj(self):
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
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)
Expand Down Expand Up @@ -56,7 +56,7 @@ def test_map2odoo_product(self):

def test_map2odoo_product_pia(self):
seg = ("1", "", ["", "EN"])
pia = (['5', ['1276', 'SA', '', '9']])
pia = ["5", ["1276", "SA", "", "9"]]
product = self.base_edifact_model.map2odoo_product(seg, pia)
self.assertEqual(product["code"], "1276")

Expand All @@ -76,6 +76,11 @@ def test_map2odoo_unit_price(self):

def test_map2odoo_date(self):
# Test with date format YYYY-MM-DD HH:MM
date_str = (['137', '202303201433', '203'])
date_str = ["137", "202303201433", "203"]
date = self.base_edifact_model.map2odoo_date(date_str)
self.assertEqual(str(date), "2023-03-20")

def test_map2odoo_description(self):
seg = ["F", "79", ["", "", "", "Description"]]
description = self.base_edifact_model.map2odoo_description(seg)
self.assertEqual(description, "Description")

0 comments on commit 5926ca2

Please sign in to comment.