Skip to content

Commit 4614721

Browse files
author
duongtq
committed
[IMP] despatch_advice_import_ubl: collect package (logistic transport units)
1 parent 1411ba4 commit 4614721

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

despatch_advice_import/wizard/despatch_advice_import.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ def process_document(self):
132132
)
133133
self.process_data(parsed_order_document)
134134

135-
def _collect_lines_by_id(self, lines_doc):
135+
def _collect_lines_by_id(self, lines_doc, key="order_line_id"):
136136
lines_by_id = {}
137137
for line in lines_doc:
138-
line_id = int(line["order_line_id"])
138+
line_id = int(line[key])
139139
if line_id in lines_by_id:
140140
lines_by_id[line_id]["qty"] += line["qty"]
141141
lines_by_id[line_id]["backorder_qty"] += line["backorder_qty"]

despatch_advice_import_ubl/tests/test_despatch_advice_import.py

+2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def test_xml_convert_to_internal_data_01(self):
110110
"date": "2020-11-16",
111111
"despatch_advice_type_code": "delivery",
112112
"estimated_delivery_date": "2020-11-17",
113+
"id": "0810805774",
113114
"lines": [
114115
{
115116
"backorder_qty": 12.0,
@@ -172,6 +173,7 @@ def test_xml_convert_to_internal_data_02(self):
172173
"date": "2020-11-16",
173174
"despatch_advice_type_code": "scheduled",
174175
"estimated_delivery_date": "2020-11-17",
176+
"id": "0810805774",
175177
"lines": [
176178
{
177179
"backorder_qty": 12.0,

despatch_advice_import_ubl/wizard/despatch_advice_import.py

+31-6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def parse_ubl_despatch_advice(self, xml_root):
3737
"cac:EstimatedDeliveryPeriod/cbc:EndDate",
3838
namespaces=ns,
3939
)
40+
order_id_xpath = xml_root.xpath("/main:DespatchAdvice/cbc:ID", namespaces=ns)
4041
order_reference_xpath = xml_root.xpath(
4142
"/main:DespatchAdvice/cac:OrderReference/cbc:ID", namespaces=ns
4243
)
@@ -66,12 +67,15 @@ def parse_ubl_despatch_advice(self, xml_root):
6667
for line in lines_xpath:
6768
res_lines.append(self.parse_ubl_despatch_advice_line(line, ns))
6869
res = {
70+
"id": order_id_xpath[0].text if order_id_xpath else "",
6971
"ref": order_reference_xpath[0].text if order_reference_xpath else "",
7072
"supplier": supplier_dict,
7173
"company": customer_dict,
72-
"despatch_advice_type_code": despatch_advice_type_code_xpath[0].text
73-
if len(despatch_advice_type_code_xpath) > 0
74-
else "",
74+
"despatch_advice_type_code": (
75+
despatch_advice_type_code_xpath[0].text
76+
if len(despatch_advice_type_code_xpath) > 0
77+
else ""
78+
),
7579
"date": len(date_xpath) and date_xpath[0].text,
7680
"estimated_delivery_date": len(estimated_delivery_date_xpath)
7781
and estimated_delivery_date_xpath[0].text,
@@ -125,6 +129,25 @@ def parse_ubl_despatch_advice_line(self, line, ns):
125129
"uom": {"unece_code": qty_xpath[0].attrib.get("unitCode")},
126130
"backorder_qty": backorder_qty,
127131
}
132+
133+
package_id_xpath = line.xpath(
134+
"cac:Shipment/cac:TransportHandlingUnit/cac:ActualPackage/cbc:ID",
135+
namespaces=ns,
136+
)
137+
package_type_xpath = line.xpath(
138+
"cac:Shipment/cac:TransportHandlingUnit/cbc:TransportHandlingUnitTypeCode",
139+
namespaces=ns,
140+
)
141+
package_weight_xpath = line.xpath(
142+
"cac:Shipment/cac:GrossWeightMeasure/cbc:Measure", namespaces=ns
143+
)
144+
if package_id_xpath or package_type_xpath:
145+
res_line["package"] = {
146+
"name": package_id_xpath[0].text if package_id_xpath else "",
147+
"type": package_type_xpath[0].text if package_type_xpath else "",
148+
"weight": package_weight_xpath[0].text if package_weight_xpath else "",
149+
}
150+
128151
defaults = self.env.context.get("despatch_advice_import__default_vals", {}).get(
129152
"lines", {}
130153
)
@@ -141,9 +164,11 @@ def ubl_parse_party(self, party_node, ns):
141164

142165
vat_xpath = party_node.xpath("cac:PartyIdentification/cbc:ID", namespaces=ns)
143166
partner_dict = {
144-
"vat": vat_xpath[0].text
145-
if vat_xpath and vat_xpath[0].attrib.get("schemeName").upper()
146-
else False,
167+
"vat": (
168+
vat_xpath[0].text
169+
if vat_xpath and vat_xpath[0].attrib.get("schemeName").upper()
170+
else False
171+
),
147172
"name": partner_name_xpath[0].text,
148173
}
149174
address_xpath = party_node.xpath("cac:PostalAddress", namespaces=ns)

0 commit comments

Comments
 (0)