From ed3dcd2427bc5c3c5957c11ec3fcb5ecc98bc5c6 Mon Sep 17 00:00:00 2001 From: thien Date: Mon, 22 Jan 2024 11:00:42 +0700 Subject: [PATCH 1/3] [UPD] base_wamas_ubl: update address export --- base_wamas_ubl/lib/wamas/test_utils.py | 52 +++++++++- ...WAMAS-SAMPLE_AUSK_AUSP-DESPATCH_ADVICE.xml | 94 +++++++++++++++++++ base_wamas_ubl/lib/wamas/utils.py | 49 ++++++++++ .../lib/wamas/wamas_grammar/ausk.py | 29 +++--- .../lib/wamas/wamas_grammar/kretk.py | 16 ++-- .../lib/wamas/wamas_grammar/weak.py | 16 ++-- .../CHECKWAMAS-SAMPLE_OUTPUT-EXCEPTION-2.txt | 2 +- .../CHECKWAMAS-SAMPLE_OUTPUT-EXCEPTION.txt | 2 +- .../samples/CHECKWAMAS-SAMPLE_OUTPUT.txt | 1 + .../samples/SIMULATEWAMAS-SAMPLE_OUTPUT.wamas | 12 +-- ...WAMAS-SAMPLE_AUSK_AUSP-DESPATCH_ADVICE.xml | 8 +- .../samples/UBL2WAMAS-SAMPLE_AUSK_AUSP.wamas | 4 +- ...MAS-SAMPLE_KRETK_KRETP-DESPATCH_ADVICE.xml | 2 + .../UBL2WAMAS-SAMPLE_KRETK_KRETP.wamas | 12 +-- .../samples/UBL2WAMAS-SAMPLE_WEAK_WEAP.wamas | 12 +-- base_wamas_ubl/tests/test_base_wamas_ubl.py | 15 ++- 16 files changed, 258 insertions(+), 68 deletions(-) create mode 100644 base_wamas_ubl/lib/wamas/tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP-DESPATCH_ADVICE.xml diff --git a/base_wamas_ubl/lib/wamas/test_utils.py b/base_wamas_ubl/lib/wamas/test_utils.py index f125e1ae69..6988e9fbee 100644 --- a/base_wamas_ubl/lib/wamas/test_utils.py +++ b/base_wamas_ubl/lib/wamas/test_utils.py @@ -1,8 +1,20 @@ import ast import unittest +import xmltodict +from dotty_dict import Dotty from freezegun import freeze_time -from utils import dict2wamas, file_open, file_path +from utils import ( + dict2wamas, + file_open, + file_path, + get_address_elements, + get_Adrs_Adr, + get_Adrs_Name, + get_Adrs_Name2, + get_Adrs_Name3, + get_Adrs_Name4, +) class TestUtils(unittest.TestCase): @@ -29,6 +41,44 @@ def testDict2wamas(self): output = dict2wamas(ast.literal_eval(str_dict_input), telegram) self.assertEqual(output, expected_output) + def testGetAddressNamePicking(self): + infile = file_open( + file_path("tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP-DESPATCH_ADVICE.xml") + ).read() + dict_item = Dotty(xmltodict.parse(infile)) + address_elements = get_address_elements(dict_item) + self.assertEqual( + address_elements, + { + "ContactName": "Chester Reed", + "PartyName": "YourCompany", + "Department": "Department_1", + "StreetName": "250 Executive Park Blvd, Suite 3400", + "AdditionalStreetName": "AdditionalStreetName_1", + }, + ) + self.assertEqual(get_Adrs_Name(address_elements), "Chester Reed") + self.assertEqual(get_Adrs_Name2(address_elements), "YourCompany") + self.assertEqual(get_Adrs_Name3(address_elements), "Department_1") + self.assertEqual( + get_Adrs_Name4(address_elements), "250 Executive Park Blvd, Suite 3400" + ) + self.assertEqual(get_Adrs_Adr(address_elements), "AdditionalStreetName_1") + + def testGetAddressNameFromDict(self): + address_elements = { + "ContactName": "Nom", + "PartyName": "YourCompany", + "Department": "Nom3", + "StreetName": "Nom4", + "AdditionalStreetName": "Adresse", + } + self.assertEqual(get_Adrs_Name(address_elements), "Nom") + self.assertEqual(get_Adrs_Name2(address_elements), "YourCompany") + self.assertEqual(get_Adrs_Name3(address_elements), "Nom3") + self.assertEqual(get_Adrs_Name4(address_elements), "Nom4") + self.assertEqual(get_Adrs_Adr(address_elements), "Adresse") + if __name__ == "__main__": unittest.main() diff --git a/base_wamas_ubl/lib/wamas/tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP-DESPATCH_ADVICE.xml b/base_wamas_ubl/lib/wamas/tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP-DESPATCH_ADVICE.xml new file mode 100644 index 0000000000..93ccce46c7 --- /dev/null +++ b/base_wamas_ubl/lib/wamas/tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP-DESPATCH_ADVICE.xml @@ -0,0 +1,94 @@ + + + 2.2 + 1673980/1700802 + + 2023-04-30 + + 1700802 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + YourCompany + + + 250 Executive Park Blvd, Suite 3400 + AdditionalStreetName_1 + Department_1 + San Francisco + 94134 + California + + US + + + + + + + + + + + Chester Reed + (979)-904-8902 + + chester.reed79@example.com + + + + + GE 2/120185 + + + 2023-04-13 + 11:00:00 + + + + Quai-22 + + + + + + 10001 + 1500 + + 000011 + + + + 7076 + + + + diff --git a/base_wamas_ubl/lib/wamas/utils.py b/base_wamas_ubl/lib/wamas/utils.py index c14d8b54a0..932ff3ce8d 100644 --- a/base_wamas_ubl/lib/wamas/utils.py +++ b/base_wamas_ubl/lib/wamas/utils.py @@ -217,6 +217,50 @@ def convert_unit_code(key, val): return val +def get_address_elements(dict_item): + return { + "ContactName": dict_item.get( + "DespatchAdvice.cac:DeliveryCustomerParty.cac:Party.cac:Contact.cbc:Name" + ), + "PartyName": dict_item.get( + "DespatchAdvice.cac:DeliveryCustomerParty." + "cac:Party.cac:PartyName.cbc:Name" + ), + "Department": dict_item.get( + "DespatchAdvice.cac:DeliveryCustomerParty." + "cac:Party.cac:PostalAddress.cbc:Department" + ), + "StreetName": dict_item.get( + "DespatchAdvice.cac:DeliveryCustomerParty." + "cac:Party.cac:PostalAddress.cbc:StreetName" + ), + "AdditionalStreetName": dict_item.get( + "DespatchAdvice.cac:DeliveryCustomerParty." + "cac:Party.cac:PostalAddress.cbc:AdditionalStreetName" + ), + } + + +def get_Adrs_Name(a): + return a["ContactName"] or a["PartyName"] + + +def get_Adrs_Name2(a): + return next(filter(None, [a["PartyName"], a["Department"], a["StreetName"]]), "") + + +def get_Adrs_Name3(a): + return next(filter(None, [a["Department"], a["StreetName"]]), "") + + +def get_Adrs_Name4(a): + return a["StreetName"] + + +def get_Adrs_Adr(a): + return a["AdditionalStreetName"] or a["StreetName"] + + def generate_wamas_line(dict_item, grammar, **kwargs): # noqa: C901 res = "" dict_parent_id = kwargs.get("dict_parent_id", {}) @@ -275,6 +319,11 @@ def generate_wamas_line(dict_item, grammar, **kwargs): # noqa: C901 args = (dict_wamas_out,) args += ast.literal_eval(re.search(r"\((.*?)\)", df_func).group(0)) df_func = "get_date_from_field" + # TODO: Consider refactoring to use classes + # or provide a better way to determine arguments. + elif "get_Adrs_" in df_func: + address_elements = get_address_elements(dict_item) + args = (address_elements,) val = globals()[df_func](*args) diff --git a/base_wamas_ubl/lib/wamas/wamas_grammar/ausk.py b/base_wamas_ubl/lib/wamas/wamas_grammar/ausk.py index 76c78a08a1..1024992a8d 100644 --- a/base_wamas_ubl/lib/wamas/wamas_grammar/ausk.py +++ b/base_wamas_ubl/lib/wamas/wamas_grammar/ausk.py @@ -106,7 +106,7 @@ "dp": False, "ubl_path": False, "df_val": False, - "df_func": False, + "df_func": "get_Adrs_Name", }, "RxAusk_Adrs_Name2": { "type": "str", @@ -114,7 +114,7 @@ "dp": False, "ubl_path": False, "df_val": False, - "df_func": False, + "df_func": "get_Adrs_Name2", }, "RxAusk_Adrs_Name3": { "type": "str", @@ -122,7 +122,7 @@ "dp": False, "ubl_path": False, "df_val": False, - "df_func": False, + "df_func": "get_Adrs_Name3", }, "RxAusk_Adrs_Name4": { "type": "str", @@ -130,7 +130,7 @@ "dp": False, "ubl_path": False, "df_val": False, - "df_func": False, + "df_func": "get_Adrs_Name4", }, "RxAusk_Adrs_Anrede": { "type": "str", @@ -146,7 +146,7 @@ "dp": False, "ubl_path": False, "df_val": False, - "df_func": False, + "df_func": "get_Adrs_Adr", }, "RxAusk_Adrs_Adr2": { "type": "str", @@ -232,10 +232,9 @@ "type": "str", "length": 40, "dp": False, - "ubl_path": "DespatchAdvice.cac:DeliveryCustomerParty.cac:Party." - "cac:Contact.cbc:Name", + "ubl_path": False, "df_val": False, - "df_func": False, + "df_func": "get_Adrs_Name", }, "RxAusk_LiefAdrs_Name2": { "type": "str", @@ -243,7 +242,7 @@ "dp": False, "ubl_path": False, "df_val": False, - "df_func": False, + "df_func": "get_Adrs_Name2", }, "RxAusk_LiefAdrs_Name3": { "type": "str", @@ -251,16 +250,15 @@ "dp": False, "ubl_path": False, "df_val": False, - "df_func": False, + "df_func": "get_Adrs_Name3", }, "RxAusk_LiefAdrs_Name4": { "type": "str", "length": 40, "dp": False, - "ubl_path": "DespatchAdvice.cac:DeliveryCustomerParty.cac:Party." - "cac:PartyName.cbc:Name", + "ubl_path": False, "df_val": False, - "df_func": False, + "df_func": "get_Adrs_Name4", }, "RxAusk_LiefAdrs_Anrede": { "type": "str", @@ -274,10 +272,9 @@ "type": "str", "length": 40, "dp": False, - "ubl_path": "DespatchAdvice.cac:DeliveryCustomerParty.cac:Party." - "cac:PostalAddress.cbc:StreetName", + "ubl_path": False, "df_val": False, - "df_func": False, + "df_func": "get_Adrs_Adr", }, "RxAusk_LiefAdrs_Adr2": { "type": "str", diff --git a/base_wamas_ubl/lib/wamas/wamas_grammar/kretk.py b/base_wamas_ubl/lib/wamas/wamas_grammar/kretk.py index 8e3b6bb64e..e1e8bc36c9 100644 --- a/base_wamas_ubl/lib/wamas/wamas_grammar/kretk.py +++ b/base_wamas_ubl/lib/wamas/wamas_grammar/kretk.py @@ -103,10 +103,9 @@ "type": "str", "length": 40, "dp": False, - "ubl_path": "DespatchAdvice.cac:DespatchSupplierParty." - "cac:Party.cac:PartyName.cbc:Name", + "ubl_path": False, "df_val": False, - "df_func": False, + "df_func": "get_Adrs_Name", }, "RxKretk_Adrs_Name2": { "type": "str", @@ -114,7 +113,7 @@ "dp": False, "ubl_path": False, "df_val": False, - "df_func": False, + "df_func": "get_Adrs_Name2", }, "RxKretk_Adrs_Name3": { "type": "str", @@ -122,7 +121,7 @@ "dp": False, "ubl_path": False, "df_val": False, - "df_func": False, + "df_func": "get_Adrs_Name3", }, "RxKretk_Adrs_Name4": { "type": "str", @@ -130,7 +129,7 @@ "dp": False, "ubl_path": False, "df_val": False, - "df_func": False, + "df_func": "get_Adrs_Name4", }, "RxKretk_Adrs_Anrede": { "type": "str", @@ -144,10 +143,9 @@ "type": "str", "length": 40, "dp": False, - "ubl_path": "DespatchAdvice.cac:DespatchSupplierParty." - "cac:Party.cac:PostalAddress.cbc:StreetName", + "ubl_path": False, "df_val": False, - "df_func": False, + "df_func": "get_Adrs_Adr", }, "RxKretk_Adrs_Adr2": { "type": "str", diff --git a/base_wamas_ubl/lib/wamas/wamas_grammar/weak.py b/base_wamas_ubl/lib/wamas/wamas_grammar/weak.py index 5481e64ff6..ad8c757884 100644 --- a/base_wamas_ubl/lib/wamas/wamas_grammar/weak.py +++ b/base_wamas_ubl/lib/wamas/wamas_grammar/weak.py @@ -103,10 +103,9 @@ "type": "str", "length": 40, "dp": False, - "ubl_path": "DespatchAdvice.cac:DespatchSupplierParty." - "cac:Party.cac:PartyName.cbc:Name", + "ubl_path": False, "df_val": False, - "df_func": False, + "df_func": "get_Adrs_Name", }, "RxWeak_Adrs_Name2": { "type": "str", @@ -114,7 +113,7 @@ "dp": False, "ubl_path": False, "df_val": False, - "df_func": False, + "df_func": "get_Adrs_Name2", }, "RxWeak_Adrs_Name3": { "type": "str", @@ -122,7 +121,7 @@ "dp": False, "ubl_path": False, "df_val": False, - "df_func": False, + "df_func": "get_Adrs_Name3", }, "RxWeak_Adrs_Name4": { "type": "str", @@ -130,7 +129,7 @@ "dp": False, "ubl_path": False, "df_val": False, - "df_func": False, + "df_func": "get_Adrs_Name4", }, "RxWeak_Adrs_Anrede": { "type": "str", @@ -144,10 +143,9 @@ "type": "str", "length": 40, "dp": False, - "ubl_path": "DespatchAdvice.cac:DespatchSupplierParty." - "cac:Party.cac:PostalAddress.cbc:StreetName", + "ubl_path": False, "df_val": False, - "df_func": False, + "df_func": "get_Adrs_Adr", }, "RxWeak_Adrs_Adr2": { "type": "str", diff --git a/base_wamas_ubl/tests/samples/CHECKWAMAS-SAMPLE_OUTPUT-EXCEPTION-2.txt b/base_wamas_ubl/tests/samples/CHECKWAMAS-SAMPLE_OUTPUT-EXCEPTION-2.txt index deb433bc0a..52176f1e99 100644 --- a/base_wamas_ubl/tests/samples/CHECKWAMAS-SAMPLE_OUTPUT-EXCEPTION-2.txt +++ b/base_wamas_ubl/tests/samples/CHECKWAMAS-SAMPLE_OUTPUT-EXCEPTION-2.txt @@ -1 +1 @@ -- Error: Length of line does not match expected length +- Error: Length of line does not match expected length \ No newline at end of file diff --git a/base_wamas_ubl/tests/samples/CHECKWAMAS-SAMPLE_OUTPUT-EXCEPTION.txt b/base_wamas_ubl/tests/samples/CHECKWAMAS-SAMPLE_OUTPUT-EXCEPTION.txt index be93fcb954..23ca1ee8a2 100644 --- a/base_wamas_ubl/tests/samples/CHECKWAMAS-SAMPLE_OUTPUT-EXCEPTION.txt +++ b/base_wamas_ubl/tests/samples/CHECKWAMAS-SAMPLE_OUTPUT-EXCEPTION.txt @@ -1 +1 @@ -- Error: Invalid telegram type: XYZ +- Error: Invalid telegram type: XYZ \ No newline at end of file diff --git a/base_wamas_ubl/tests/samples/CHECKWAMAS-SAMPLE_OUTPUT.txt b/base_wamas_ubl/tests/samples/CHECKWAMAS-SAMPLE_OUTPUT.txt index 58f98ea63f..2b975354b8 100644 --- a/base_wamas_ubl/tests/samples/CHECKWAMAS-SAMPLE_OUTPUT.txt +++ b/base_wamas_ubl/tests/samples/CHECKWAMAS-SAMPLE_OUTPUT.txt @@ -36,3 +36,4 @@ } ] } + \ No newline at end of file diff --git a/base_wamas_ubl/tests/samples/SIMULATEWAMAS-SAMPLE_OUTPUT.wamas b/base_wamas_ubl/tests/samples/SIMULATEWAMAS-SAMPLE_OUTPUT.wamas index 2eb5206655..e676f829bf 100644 --- a/base_wamas_ubl/tests/samples/SIMULATEWAMAS-SAMPLE_OUTPUT.wamas +++ b/base_wamas_ubl/tests/samples/SIMULATEWAMAS-SAMPLE_OUTPUT.wamas @@ -1,6 +1,6 @@ -WAMAS ODOO 00000120231220091116WEAKQ0051000130377 HOST 19700101010000 19700101010000 20231220091116 0001040 -WAMAS ODOO 00000220231220091116WEAPQ0050000130377 000130377 HOST 000020 0001151 00000DISPONIBLE 000001536000000000000000 BOUT N -WAMAS ODOO 00000320231220091116WEAPQ0050000130377 000130377 HOST 000030 0001156 00000DISPONIBLE 000005184000000000000000 PET N -WAMAS ODOO 00000420231220091116WEAPQ0050000130377 000130377 HOST 000040 0001160 00000DISPONIBLE 000003840000000000000000 BOUT N -WAMAS ODOO 00000520231220091116WEAPQ0050000130377 000130377 HOST 000050 0001162 00000DISPONIBLE 000003072000000000000000 PET N -WAMAS ODOO 00000620231220091116WEAPQ0050000130377 000130377 HOST 000060 0001176 00000DISPONIBLE 000003024000000000000000 PET N \ No newline at end of file +WAMAS ODOO 00000120230501000000WEAKQ0051000130377 HOST 19700101010000 19700101010000 20230501000000 0001040 +WAMAS ODOO 00000220230501000000WEAPQ0050000130377 000130377 HOST 000020 0001151 00000DISPONIBLE 000001536000000000000000 BOUT N +WAMAS ODOO 00000320230501000000WEAPQ0050000130377 000130377 HOST 000030 0001156 00000DISPONIBLE 000005184000000000000000 PET N +WAMAS ODOO 00000420230501000000WEAPQ0050000130377 000130377 HOST 000040 0001160 00000DISPONIBLE 000003840000000000000000 BOUT N +WAMAS ODOO 00000520230501000000WEAPQ0050000130377 000130377 HOST 000050 0001162 00000DISPONIBLE 000003072000000000000000 PET N +WAMAS ODOO 00000620230501000000WEAPQ0050000130377 000130377 HOST 000060 0001176 00000DISPONIBLE 000003024000000000000000 PET N \ No newline at end of file diff --git a/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP-DESPATCH_ADVICE.xml b/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP-DESPATCH_ADVICE.xml index 836c7d2de4..69f515209b 100644 --- a/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP-DESPATCH_ADVICE.xml +++ b/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP-DESPATCH_ADVICE.xml @@ -37,10 +37,12 @@ - YourCompany + Name - 250 Executive Park Blvd, Suite 3400 + StreetName + Department + AdditionalStreetName San Francisco 94134 California @@ -56,7 +58,7 @@ - Chester Reed + (979)-904-8902 chester.reed79@example.com diff --git a/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP.wamas b/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP.wamas index 9cc8b2cb81..f6dcfb2415 100644 --- a/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP.wamas +++ b/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP.wamas @@ -1,2 +1,2 @@ -ODOO WAMAS 00000120230501000000AUSK000560001673980/1700802 HOST 1700802 000 Chester Reed YourCompany 250 Executive Park Blvd, Suite 3400 94134 San Francisco California US (979)-904-8902 chester.reed79@example.com 20230413130000Quai-22 FRUEH FRUEHGE 2/120185 HOST 00000000000000000000000000 000 ST Def_Strat -ODOO WAMAS 00000220230501000000AUSP000540001673980/1700802 HOST 10001 0000020007076 00000 DISPONIBLE 0000000000000000000000000000 000001500000PET 00000000000000 NN N 0000N \ No newline at end of file +ODOO WAMAS 00000120230501020000AUSK000560001673980/1700802 HOST 1700802 000 Name Name Department StreetName AdditionalStreetName Name Name Department StreetName AdditionalStreetName 94134 San Francisco California US (979)-904-8902 chester.reed79@example.com 20230413130000Quai-22 FRUEH FRUEHGE 2/120185 HOST 00000000000000000000000000 001 ST Def_Strat +ODOO WAMAS 00000220230501020000AUSP000540001700802 HOST 10001 0000110007076 00000 DISPONIBLE 0000000000000000000000000000 000001500000PET 00000000000000 NN N 0000N \ No newline at end of file diff --git a/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_KRETK_KRETP-DESPATCH_ADVICE.xml b/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_KRETK_KRETP-DESPATCH_ADVICE.xml index 52119aeaf2..02d69f3142 100644 --- a/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_KRETK_KRETP-DESPATCH_ADVICE.xml +++ b/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_KRETK_KRETP-DESPATCH_ADVICE.xml @@ -37,6 +37,8 @@ 250 Executive Park Blvd, Suite 3400 + AdditionalStreetName_1 + Department_1 San Francisco 94134 California diff --git a/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_KRETK_KRETP.wamas b/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_KRETK_KRETP.wamas index e9d02d2445..4cdbf78dc8 100644 --- a/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_KRETK_KRETP.wamas +++ b/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_KRETK_KRETP.wamas @@ -1,6 +1,6 @@ -ODOO WAMAS 00000120230501020000KRETK0051000130377 HOST STDMAN0001040 MyCompany 1839 Arbor Way California 95380 Turlock US (623)-853-7197 wood.corner26@example.com 20230427000000 -ODOO WAMAS 00000220230501020000KRETP0046000130377 HOST 0000200001151 0000020001151 00000DISPONIBLE 000001536000BOUT N -ODOO WAMAS 00000320230501020000KRETP0046000130377 HOST 0000300001156 0000030001156 00000DISPONIBLE 000005184000PET N -ODOO WAMAS 00000420230501020000KRETP0046000130377 HOST 0000400001160 0000040001160 00000DISPONIBLE 000003840000BOUT N -ODOO WAMAS 00000520230501020000KRETP0046000130377 HOST 0000500001162 0000050001162 00000DISPONIBLE 000003072000PET N -ODOO WAMAS 00000620230501020000KRETP0046000130377 HOST 0000600001176 0000060001176 00000DISPONIBLE 000003024000PET N \ No newline at end of file +ODOO WAMAS 00000120230501020000KRETK0051000130377 HOST STDMAN0001040 STDMAN0001040 Chester Reed YourCompany Department_1 250 Executive Park Blvd, Suite 3400 AdditionalStreetName_1 California 95380 Turlock US (623)-853-7197 wood.corner26@example.com 20230427020000 +ODOO WAMAS 00000220230501020000KRETP0046000130377 HOST 0001 0000020001151 00000DISPONIBLE 000001536000BOUT N +ODOO WAMAS 00000320230501020000KRETP0046000130377 HOST 0002 0000030001156 00000DISPONIBLE 000005184000PET N +ODOO WAMAS 00000420230501020000KRETP0046000130377 HOST 0003 0000040001160 00000DISPONIBLE 000003840000BOUT N +ODOO WAMAS 00000520230501020000KRETP0046000130377 HOST 0004 0000050001162 00000DISPONIBLE 000003072000PET N +ODOO WAMAS 00000620230501020000KRETP0046000130377 HOST 0005 0000060001176 00000DISPONIBLE 000003024000PET N \ No newline at end of file diff --git a/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_WEAK_WEAP.wamas b/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_WEAK_WEAP.wamas index f34f47cf71..d978d1aa09 100644 --- a/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_WEAK_WEAP.wamas +++ b/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_WEAK_WEAP.wamas @@ -1,6 +1,6 @@ -ODOO WAMAS 00000120230501020000WEAK00050000130377 HOST STDMAN0001040 MyCompany 1839 Arbor Way California 95380 Turlock US (623)-853-7197 wood.corner26@example.com 20230427000000 -ODOO WAMAS 00000220230501020000WEAP00045000130377 HOST 0000200001151 0000020001151 00000 NDISPONIBLE 000001536000BOUT NORMAL 20230501020000 202305010000007910063 NNLG -ODOO WAMAS 00000320230501020000WEAP00045000130377 HOST 0000300001156 0000030001156 00000 NDISPONIBLE 000005184000PET NORMAL 20230501020000 202305010000007910105 NNLG -ODOO WAMAS 00000420230501020000WEAP00045000130377 HOST 0000400001160 0000040001160 00000 NDISPONIBLE 000003840000BOUT NORMAL 20230501020000 202305010000007910004 NNLG -ODOO WAMAS 00000520230501020000WEAP00045000130377 HOST 0000500001162 0000050001162 00000 NDISPONIBLE 000003072000PET NORMAL 20230501020000 2023050100000012156876 NNLG -ODOO WAMAS 00000620230501020000WEAP00045000130377 HOST 0000600001176 0000060001176 00000 NDISPONIBLE 000003024000PET NORMAL 20230501020000 202305010000007910044 NNLG \ No newline at end of file +ODOO WAMAS 00000120230501020000WEAK00050000130377 HOST STDMAN0001040 STDMAN0001040 Chester Reed YourCompany 250 Executive Park Blvd, Suite 3400 250 Executive Park Blvd, Suite 3400 250 Executive Park Blvd, Suite 3400 California 95380 Turlock US (623)-853-7197 wood.corner26@example.com 20230427020000 +ODOO WAMAS 00000220230501020000WEAP00045000130377 HOST 0001 0000020001151 00000 NDISPONIBLE 000001536000BOUT NORMAL 20230501020000 202305010200007910063 NNLG +ODOO WAMAS 00000320230501020000WEAP00045000130377 HOST 0002 0000030001156 00000 NDISPONIBLE 000005184000PET NORMAL 20230501020000 202305010200007910105 NNLG +ODOO WAMAS 00000420230501020000WEAP00045000130377 HOST 0003 0000040001160 00000 NDISPONIBLE 000003840000BOUT NORMAL 20230501020000 202305010200007910004 NNLG +ODOO WAMAS 00000520230501020000WEAP00045000130377 HOST 0004 0000050001162 00000 NDISPONIBLE 000003072000PET NORMAL 20230501020000 2023050102000012156876 NNLG +ODOO WAMAS 00000620230501020000WEAP00045000130377 HOST 0005 0000060001176 00000 NDISPONIBLE 000003024000PET NORMAL 20230501020000 202305010200007910044 NNLG \ No newline at end of file diff --git a/base_wamas_ubl/tests/test_base_wamas_ubl.py b/base_wamas_ubl/tests/test_base_wamas_ubl.py index 3eb3784420..4b58bcd200 100644 --- a/base_wamas_ubl/tests/test_base_wamas_ubl.py +++ b/base_wamas_ubl/tests/test_base_wamas_ubl.py @@ -4,7 +4,6 @@ from ast import literal_eval from base64 import b64decode, b64encode -from difflib import SequenceMatcher from freezegun import freeze_time @@ -78,9 +77,6 @@ def setUpClass(cls): }, } - def _is_string_similar(self, s1, s2, threshold=0.9): - return SequenceMatcher(a=s1, b=s2).ratio() > threshold - @freeze_time("2023-05-01") def _convert_wamas2ubl(self, input_file, expected_output_files): str_input = file_open(input_file, "r").read() @@ -99,8 +95,9 @@ def _convert_ubl2wamas(self, input_file, expected_output_file, telegram_type): expected_output = ( file_open(expected_output_file, "r").read().encode("iso-8859-1") ) - self.assertTrue(self._is_string_similar(output, expected_output)) + self.assertEqual(output, expected_output) + @freeze_time("2023-05-01") def _wamas_ubl_wiz_check(self, input_file, expected_output_file): str_input = file_open(input_file, "r").read() str_expected_output = file_open(expected_output_file, "r").read() @@ -112,8 +109,9 @@ def _wamas_ubl_wiz_check(self, input_file, expected_output_file): wizard._onchange_wamas_filename() self.assertFalse(wizard.output) wizard.btn_check() - self.assertTrue(self._is_string_similar(wizard.output, str_expected_output)) + self.assertEqual(wizard.output, str_expected_output) + @freeze_time("2023-05-01") def _wamas_ubl_wiz_simulate( self, input_file, expected_output_file, state="success" ): @@ -131,10 +129,10 @@ def _wamas_ubl_wiz_simulate( if state == "success": output = b64decode(wizard.output_wamas_file).decode("iso-8859-1") expected_output = file_open(expected_output_file, "r").read() - self.assertTrue(self._is_string_similar(output, expected_output)) + self.assertEqual(output, expected_output) else: expected_output = file_open(expected_output_file, "r").read() - self.assertTrue(self._is_string_similar(wizard.output, expected_output)) + self.assertEqual(wizard.output, expected_output) def test_convert_wamas2ubl(self): dict_data = { @@ -234,6 +232,7 @@ def test_export_dict2wamas(self): output = self.base_wamas_ubl.dict2wamas(dict_input, "LST") self.assertEqual(output, expected_output) + @freeze_time("2023-12-21 04:12:51") def test_get_wamas_type(self): dict_data = { "input": "base_wamas_ubl/tests/samples/CHECKWAMAS-SAMPLE_INPUT.wamas", From 2b0730d6e973fc2b7f4fc30881eb1c0b96dcb539 Mon Sep 17 00:00:00 2001 From: thien Date: Mon, 29 Jan 2024 18:39:27 +0700 Subject: [PATCH 2/3] [IMP] base_wamas_ubl: Customer, Supplier export fields correction --- base_wamas_ubl/lib/wamas/wamas_grammar/kst.py | 18 +++++++++--------- base_wamas_ubl/lib/wamas/wamas_grammar/lst.py | 10 +++++----- .../samples/DICT2WAMAS-SAMPLE_OUTPUT.wamas | 2 +- .../samples/TELEGRAM-SAMPLE-KST_INPUT.dict | 8 ++++++++ .../samples/TELEGRAM-SAMPLE-KST_OUTPUT.wamas | 2 +- .../samples/TELEGRAM-SAMPLE-LST_INPUT.dict | 4 ++++ .../samples/TELEGRAM-SAMPLE-LST_OUTPUT.wamas | 2 +- 7 files changed, 29 insertions(+), 17 deletions(-) diff --git a/base_wamas_ubl/lib/wamas/wamas_grammar/kst.py b/base_wamas_ubl/lib/wamas/wamas_grammar/kst.py index 49e053ddf9..c5a36d5be1 100644 --- a/base_wamas_ubl/lib/wamas/wamas_grammar/kst.py +++ b/base_wamas_ubl/lib/wamas/wamas_grammar/kst.py @@ -67,7 +67,7 @@ "type": "str", "length": 40, "dp": False, - "dict_key": False, + "dict_key": "delivery_name2", "df_val": False, "df_func": False, }, @@ -75,7 +75,7 @@ "type": "str", "length": 40, "dp": False, - "dict_key": False, + "dict_key": "delivery_name3", "df_val": False, "df_func": False, }, @@ -83,7 +83,7 @@ "type": "str", "length": 40, "dp": False, - "dict_key": False, + "dict_key": "delivery_name4", "df_val": False, "df_func": False, }, @@ -91,7 +91,7 @@ "type": "str", "length": 15, "dp": False, - "dict_key": "title", + "dict_key": "delivery_title", "df_val": False, "df_func": False, }, @@ -107,7 +107,7 @@ "type": "str", "length": 40, "dp": False, - "dict_key": "delivery_street2", + "dict_key": False, "df_val": False, "df_func": False, }, @@ -194,7 +194,7 @@ "type": "str", "length": 40, "dp": False, - "dict_key": False, + "dict_key": "invoicing_name2", "df_val": False, "df_func": False, }, @@ -202,7 +202,7 @@ "type": "str", "length": 40, "dp": False, - "dict_key": False, + "dict_key": "invoicing_name3", "df_val": False, "df_func": False, }, @@ -210,7 +210,7 @@ "type": "str", "length": 40, "dp": False, - "dict_key": False, + "dict_key": "invoicing_name4", "df_val": False, "df_func": False, }, @@ -234,7 +234,7 @@ "type": "str", "length": 40, "dp": False, - "dict_key": "invoicing_street2", + "dict_key": False, "df_val": False, "df_func": False, }, diff --git a/base_wamas_ubl/lib/wamas/wamas_grammar/lst.py b/base_wamas_ubl/lib/wamas/wamas_grammar/lst.py index aa20febf1b..f6720d6feb 100644 --- a/base_wamas_ubl/lib/wamas/wamas_grammar/lst.py +++ b/base_wamas_ubl/lib/wamas/wamas_grammar/lst.py @@ -67,7 +67,7 @@ "type": "str", "length": 40, "dp": False, - "dict_key": False, + "dict_key": "name2", "df_val": False, "df_func": False, }, @@ -75,7 +75,7 @@ "type": "str", "length": 40, "dp": False, - "dict_key": False, + "dict_key": "name3", "df_val": False, "df_func": False, }, @@ -83,7 +83,7 @@ "type": "str", "length": 40, "dp": False, - "dict_key": False, + "dict_key": "name4", "df_val": False, "df_func": False, }, @@ -107,7 +107,7 @@ "type": "str", "length": 40, "dp": False, - "dict_key": "street2", + "dict_key": False, "df_val": False, "df_func": False, }, @@ -131,7 +131,7 @@ "type": "str", "length": 40, "dp": False, - "dict_key": "state", + "dict_key": "lang", "df_val": False, "df_func": False, }, diff --git a/base_wamas_ubl/tests/samples/DICT2WAMAS-SAMPLE_OUTPUT.wamas b/base_wamas_ubl/tests/samples/DICT2WAMAS-SAMPLE_OUTPUT.wamas index 7938ce3514..af473c1828 100644 --- a/base_wamas_ubl/tests/samples/DICT2WAMAS-SAMPLE_OUTPUT.wamas +++ b/base_wamas_ubl/tests/samples/DICT2WAMAS-SAMPLE_OUTPUT.wamas @@ -1 +1 @@ -ODOO WAMAS 00000120231221051251LST0000510000001 Adam Smith adam@dayrep.com 79782 Sand Springs Texas US 432-393-1264 aaa Standard 0N JStandard N \ No newline at end of file +ODOO WAMAS 00000120231221051251LST0000510000001 Adam Smith adam@dayrep.com 79782 Sand Springs US 432-393-1264 aaa Standard 0N JStandard N \ No newline at end of file diff --git a/base_wamas_ubl/tests/samples/TELEGRAM-SAMPLE-KST_INPUT.dict b/base_wamas_ubl/tests/samples/TELEGRAM-SAMPLE-KST_INPUT.dict index bf81ee7d35..73f3f2807c 100644 --- a/base_wamas_ubl/tests/samples/TELEGRAM-SAMPLE-KST_INPUT.dict +++ b/base_wamas_ubl/tests/samples/TELEGRAM-SAMPLE-KST_INPUT.dict @@ -1,6 +1,10 @@ { "ref": "113", "delivery_name": "Adam Smith", + "delivery_name2": "Delivery Name 2", + "delivery_name3": "Delivery Name 3", + "delivery_name4": "Delivery Name 4", + "delivery_title": "Delivery Title", "delivery_street": "3273 Laurel Lane", "delivery_street2": "", "delivery_zip": "79782", @@ -11,6 +15,10 @@ "delivery_email": "aaa", "delivery_street": "adam@dayrep.com", "invoicing_name": "Adam Smith", + "invoicing_name2": "Invoicing Name 2", + "invoicing_name3": "Invoicing Name 3", + "invoicing_name4": "Invoicing Name 4", + "invoicing_title": "invoicing Title", "invoicing_street": "3273 Laurel Lane", "invoicing_street2": "", "invoicing_zip": "79782", diff --git a/base_wamas_ubl/tests/samples/TELEGRAM-SAMPLE-KST_OUTPUT.wamas b/base_wamas_ubl/tests/samples/TELEGRAM-SAMPLE-KST_OUTPUT.wamas index 51d4030385..c359ae822f 100644 --- a/base_wamas_ubl/tests/samples/TELEGRAM-SAMPLE-KST_OUTPUT.wamas +++ b/base_wamas_ubl/tests/samples/TELEGRAM-SAMPLE-KST_OUTPUT.wamas @@ -1 +1 @@ -ODOO WAMAS 00000120231221051251KST000052000113 Adam Smith adam@dayrep.com 79782 Sand Springs Texas US 432-393-1264 aaa Adam Smith adam@dayrep.com 79782 Sand Springs Texas US 432-393-1264 aaa 000000Standard JNNNJJNJJN0000 0Standard NNJN N \ No newline at end of file +ODOO WAMAS 00000120231221051251KST000052000113 Adam Smith Delivery Name 2 Delivery Name 3 Delivery Name 4 Delivery Title adam@dayrep.com 79782 Sand Springs Texas US 432-393-1264 aaa Adam Smith Invoicing Name 2 Invoicing Name 3 Invoicing Name 4 adam@dayrep.com 79782 Sand Springs Texas US 432-393-1264 aaa 000000Standard JNNNJJNJJN0000 0Standard NNJN N \ No newline at end of file diff --git a/base_wamas_ubl/tests/samples/TELEGRAM-SAMPLE-LST_INPUT.dict b/base_wamas_ubl/tests/samples/TELEGRAM-SAMPLE-LST_INPUT.dict index 32d7998e69..da8523a53c 100644 --- a/base_wamas_ubl/tests/samples/TELEGRAM-SAMPLE-LST_INPUT.dict +++ b/base_wamas_ubl/tests/samples/TELEGRAM-SAMPLE-LST_INPUT.dict @@ -1,6 +1,10 @@ { "ref": "0001", "name": "Adam Smith", + "name2": "Name 2", + "name3": "Name 3", + "name4": "Name 4", + "lang": "EN_en", "street": "3273 Laurel Lane", "street2": "", "zip": "79782", diff --git a/base_wamas_ubl/tests/samples/TELEGRAM-SAMPLE-LST_OUTPUT.wamas b/base_wamas_ubl/tests/samples/TELEGRAM-SAMPLE-LST_OUTPUT.wamas index ca045062a6..774f919480 100644 --- a/base_wamas_ubl/tests/samples/TELEGRAM-SAMPLE-LST_OUTPUT.wamas +++ b/base_wamas_ubl/tests/samples/TELEGRAM-SAMPLE-LST_OUTPUT.wamas @@ -1 +1 @@ -ODOO WAMAS 00000120231221051251LST0000510000001 Adam Smith 3273 Laurel Lane 79782 Sand Springs Texas US 432-393-1264 aaa https://testing.com Standard 0N JStandard N \ No newline at end of file +ODOO WAMAS 00000120231221051251LST0000510000001 Adam Smith Name 2 Name 3 Name 4 3273 Laurel Lane 79782 Sand Springs EN_en US 432-393-1264 aaa https://testing.com Standard 0N JStandard N \ No newline at end of file From 2bdd2690ba7085ed408b715e59e5c01e8393b995 Mon Sep 17 00:00:00 2001 From: Tran Anh Tuan Date: Wed, 24 Jan 2024 11:50:22 +0700 Subject: [PATCH 3/3] [FIX] base_wamas_ubl: Fix bug wamas2ubl AUSKQ has wrong value in 'IvAusk_ExtRef' field --- base_wamas_ubl/lib/wamas/wamas2ubl.py | 2 +- .../WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ-DESPATCH_ADVICE.xml | 2 +- .../tests/samples/WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ.wamas | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/base_wamas_ubl/lib/wamas/wamas2ubl.py b/base_wamas_ubl/lib/wamas/wamas2ubl.py index 6c3d358f16..c5cfb5652f 100755 --- a/base_wamas_ubl/lib/wamas/wamas2ubl.py +++ b/base_wamas_ubl/lib/wamas/wamas2ubl.py @@ -87,7 +87,7 @@ def _prepare_pickings(data): packages = {} for order in data["AUSKQ"]: - order_id = order["IvAusk_AusId_AusNr"] + order_id = order["IvAusk_ExtRef"] _convert_float_field(order) if order_id not in pickings: order["lines"] = [] diff --git a/base_wamas_ubl/tests/samples/WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ-DESPATCH_ADVICE.xml b/base_wamas_ubl/tests/samples/WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ-DESPATCH_ADVICE.xml index c080c6f393..a1123bdc30 100644 --- a/base_wamas_ubl/tests/samples/WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ-DESPATCH_ADVICE.xml +++ b/base_wamas_ubl/tests/samples/WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ-DESPATCH_ADVICE.xml @@ -3,7 +3,7 @@ GE 2/120185 2023-05-01 - 1701778 + 1673982/1701778 diff --git a/base_wamas_ubl/tests/samples/WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ.wamas b/base_wamas_ubl/tests/samples/WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ.wamas index d4015c8888..4d70351d18 100644 --- a/base_wamas_ubl/tests/samples/WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ.wamas +++ b/base_wamas_ubl/tests/samples/WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ.wamas @@ -1,4 +1,4 @@ -WAMAS ODOO 00005620230413110200AUSKQ00520001673982/1701778 HOST 1701778 0004009542 202304140000002023041305252320230413110128GE 2/120185 HOST +WAMAS ODOO 00005620230413110200AUSKQ00520001673982/1701778 HOST 1673982/1701778 0004009542 202304140000002023041305252320230413110128GE 2/120185 HOST WAMAS ODOO 00000120230413110200WATEKQ054376401426411929180QUAI-22 000000000000000000000000 0000GE 2/120185 HOST PE 000740ST9016000000314700 WAMAS ODOO 00000220230413110200WATEPQ050 20240413 12 eCAM 008610 NN20240413000001TETRA 0001673982/1701778 HOST 00010100015455 00000000000007000000000000000DISPONIBLE 376401426411929180 WAMAS ODOO 00000320230413110200WATEPQ050 20240413 12 eCAM 008610 NN20240413000001TETRA 0001673982/1701778 HOST 00010100015455 00000000000008000000000000000DISPONIBLE 376401426411929180