Skip to content

Commit

Permalink
Merge PR #913 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by simahawk
  • Loading branch information
OCA-git-bot committed Jan 31, 2024
2 parents ba77365 + 2bdd269 commit ee562fa
Show file tree
Hide file tree
Showing 26 changed files with 290 additions and 88 deletions.
52 changes: 51 additions & 1 deletion base_wamas_ubl/lib/wamas/test_utils.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<DespatchAdvice xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns="urn:oasis:names:specification:ubl:schema:xsd:DespatchAdvice-2">
<cbc:UBLVersionID>2.2</cbc:UBLVersionID>
<cbc:ID>1673980/1700802</cbc:ID>
<cbc:Note/>
<cbc:IssueDate>2023-04-30</cbc:IssueDate>
<cac:OrderReference>
<cbc:ID>1700802</cbc:ID>
</cac:OrderReference>
<cac:DespatchSupplierParty>
<cac:Party>
<cac:PartyName>
<cbc:Name></cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:StreetName></cbc:StreetName>
<cbc:CityName></cbc:CityName>
<cbc:PostalZone></cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode></cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
<cac:PartyTaxScheme>
<cbc:CompanyID></cbc:CompanyID>
<cac:TaxScheme>
<cbc:ID></cbc:ID>
<cbc:TaxTypeCode></cbc:TaxTypeCode>
</cac:TaxScheme>
</cac:PartyTaxScheme>
<cac:Contact>
<cbc:Name></cbc:Name>
<cbc:Telephone></cbc:Telephone>
<cbc:ElectronicMail></cbc:ElectronicMail>
</cac:Contact>
</cac:Party>
</cac:DespatchSupplierParty>
<cac:DeliveryCustomerParty>
<cac:Party>
<cac:PartyName>
<cbc:Name>YourCompany</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:StreetName>250 Executive Park Blvd, Suite 3400</cbc:StreetName>
<cbc:AdditionalStreetName>AdditionalStreetName_1</cbc:AdditionalStreetName>
<cbc:Department>Department_1</cbc:Department>
<cbc:CityName>San Francisco</cbc:CityName>
<cbc:PostalZone>94134</cbc:PostalZone>
<cbc:CountrySubentity>California</cbc:CountrySubentity>
<cac:Country>
<cbc:IdentificationCode>US</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
<cac:PartyTaxScheme>
<cbc:CompanyID></cbc:CompanyID>
<cac:TaxScheme>
<cbc:ID></cbc:ID>
<cbc:TaxTypeCode></cbc:TaxTypeCode>
</cac:TaxScheme>
</cac:PartyTaxScheme>
<cac:Contact>
<cbc:Name>Chester Reed</cbc:Name>
<cbc:Telephone>(979)-904-8902</cbc:Telephone>
<cbc:Telefax></cbc:Telefax>
<cbc:ElectronicMail>chester.reed79@example.com</cbc:ElectronicMail>
</cac:Contact>
</cac:Party>
</cac:DeliveryCustomerParty>
<cac:Shipment>
<cbc:ID>GE 2/120185</cbc:ID>
<cac:Delivery>
<cac:EstimatedDeliveryPeriod>
<cbc:EndDate>2023-04-13</cbc:EndDate>
<cbc:EndTime>11:00:00</cbc:EndTime>
</cac:EstimatedDeliveryPeriod>
<cac:Despatch>
<cac:DespatchLocation>
<cbc:ID>Quai-22</cbc:ID>
</cac:DespatchLocation>
</cac:Despatch>
</cac:Delivery>
</cac:Shipment>
<cac:DespatchLine>
<cbc:ID>10001</cbc:ID>
<cbc:DeliveredQuantity unitCode="XBO">1500</cbc:DeliveredQuantity>
<cac:OrderLineReference>
<cbc:LineID>000011</cbc:LineID>
</cac:OrderLineReference>
<cac:Item>
<cac:SellersItemIdentification>
<cbc:ID>7076</cbc:ID>
</cac:SellersItemIdentification>
</cac:Item>
</cac:DespatchLine>
</DespatchAdvice>
49 changes: 49 additions & 0 deletions base_wamas_ubl/lib/wamas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", {})
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion base_wamas_ubl/lib/wamas/wamas2ubl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"] = []
Expand Down
29 changes: 13 additions & 16 deletions base_wamas_ubl/lib/wamas/wamas_grammar/ausk.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,31 @@
"dp": False,
"ubl_path": False,
"df_val": False,
"df_func": False,
"df_func": "get_Adrs_Name",
},
"RxAusk_Adrs_Name2": {
"type": "str",
"length": 40,
"dp": False,
"ubl_path": False,
"df_val": False,
"df_func": False,
"df_func": "get_Adrs_Name2",
},
"RxAusk_Adrs_Name3": {
"type": "str",
"length": 40,
"dp": False,
"ubl_path": False,
"df_val": False,
"df_func": False,
"df_func": "get_Adrs_Name3",
},
"RxAusk_Adrs_Name4": {
"type": "str",
"length": 40,
"dp": False,
"ubl_path": False,
"df_val": False,
"df_func": False,
"df_func": "get_Adrs_Name4",
},
"RxAusk_Adrs_Anrede": {
"type": "str",
Expand All @@ -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",
Expand Down Expand Up @@ -232,35 +232,33 @@
"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",
"length": 40,
"dp": False,
"ubl_path": False,
"df_val": False,
"df_func": False,
"df_func": "get_Adrs_Name2",
},
"RxAusk_LiefAdrs_Name3": {
"type": "str",
"length": 40,
"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",
Expand All @@ -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",
Expand Down
16 changes: 7 additions & 9 deletions base_wamas_ubl/lib/wamas/wamas_grammar/kretk.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,34 +103,33 @@
"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",
"length": 40,
"dp": False,
"ubl_path": False,
"df_val": False,
"df_func": False,
"df_func": "get_Adrs_Name2",
},
"RxKretk_Adrs_Name3": {
"type": "str",
"length": 40,
"dp": False,
"ubl_path": False,
"df_val": False,
"df_func": False,
"df_func": "get_Adrs_Name3",
},
"RxKretk_Adrs_Name4": {
"type": "str",
"length": 40,
"dp": False,
"ubl_path": False,
"df_val": False,
"df_func": False,
"df_func": "get_Adrs_Name4",
},
"RxKretk_Adrs_Anrede": {
"type": "str",
Expand All @@ -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",
Expand Down
Loading

0 comments on commit ee562fa

Please sign in to comment.