Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] despatch_advice_import_ubl : collect package (logistic transport units) #945

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions despatch_advice_import/wizard/despatch_advice_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ def process_document(self):
)
self.process_data(parsed_order_document)

def _collect_lines_by_id(self, lines_doc):
def _collect_lines_by_id(self, lines_doc, key="order_line_id"):
lines_by_id = {}
for line in lines_doc:
line_id = int(line["order_line_id"])
line_id = int(line[key])
if line_id in lines_by_id:
lines_by_id[line_id]["qty"] += line["qty"]
lines_by_id[line_id]["backorder_qty"] += line["backorder_qty"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<cbc:ID>0810805774</cbc:ID>
<cbc:ID>{picking_name}</cbc:ID>
<cbc:IssueDate>2020-11-16</cbc:IssueDate>
<cbc:DespatchAdviceTypeCode>scheduled</cbc:DespatchAdviceTypeCode>
<cac:OrderReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<cbc:ID>0810805774</cbc:ID>
<cbc:ID>{picking_name}</cbc:ID>
<cbc:IssueDate>2020-11-16</cbc:IssueDate>
<cbc:DespatchAdviceTypeCode>scheduled</cbc:DespatchAdviceTypeCode>
<cac:OrderReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def test_xml_convert_to_internal_data_01(self):
All the fields are filled into the internal data structure.
"""
xml_content = self.despatch_advice_xml1.decode("utf-8").format(
picking_name="0810805774",
order_id=self.purchase_order.name,
line_1_id=self.line1.id,
line_1_qty=self.line1.product_qty,
Expand All @@ -110,6 +111,7 @@ def test_xml_convert_to_internal_data_01(self):
"date": "2020-11-16",
"despatch_advice_type_code": "delivery",
"estimated_delivery_date": "2020-11-17",
"id": "0810805774",
"lines": [
{
"backorder_qty": 12.0,
Expand Down Expand Up @@ -149,6 +151,7 @@ def test_xml_convert_to_internal_data_02(self):
All the fields are filled into the internal data structure.
"""
xml_content = self.despatch_advice_xml2.decode("utf-8").format(
picking_name="0810805774",
line_1_id=self.line1.id,
line_1_order_id=self.purchase_order.name,
line_1_qty=self.line1.product_qty,
Expand All @@ -172,6 +175,7 @@ def test_xml_convert_to_internal_data_02(self):
"date": "2020-11-16",
"despatch_advice_type_code": "scheduled",
"estimated_delivery_date": "2020-11-17",
"id": "0810805774",
"lines": [
{
"backorder_qty": 12.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ def test_despatch_advice_import(self):
self.assertTrue(po_moves)

xml_content2 = self.despatch_advice_xml2.decode("utf-8").format(
picking_name="0810805774",
order_id=self.purchase_order.name,
line_3_id=self.line3.id,
line_6_id=self.line6.id,
Expand Down
37 changes: 31 additions & 6 deletions despatch_advice_import_ubl/wizard/despatch_advice_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"cac:EstimatedDeliveryPeriod/cbc:EndDate",
namespaces=ns,
)
order_id_xpath = xml_root.xpath("/main:DespatchAdvice/cbc:ID", namespaces=ns)
order_reference_xpath = xml_root.xpath(
"/main:DespatchAdvice/cac:OrderReference/cbc:ID", namespaces=ns
)
Expand Down Expand Up @@ -66,12 +67,15 @@
for line in lines_xpath:
res_lines.append(self.parse_ubl_despatch_advice_line(line, ns))
res = {
"id": order_id_xpath[0].text if order_id_xpath else "",
"ref": order_reference_xpath[0].text if order_reference_xpath else "",
"supplier": supplier_dict,
"company": customer_dict,
"despatch_advice_type_code": despatch_advice_type_code_xpath[0].text
if len(despatch_advice_type_code_xpath) > 0
else "",
"despatch_advice_type_code": (
despatch_advice_type_code_xpath[0].text
if len(despatch_advice_type_code_xpath) > 0
else ""
),
"date": len(date_xpath) and date_xpath[0].text,
"estimated_delivery_date": len(estimated_delivery_date_xpath)
and estimated_delivery_date_xpath[0].text,
Expand Down Expand Up @@ -125,6 +129,25 @@
"uom": {"unece_code": qty_xpath[0].attrib.get("unitCode")},
"backorder_qty": backorder_qty,
}

package_id_xpath = line.xpath(
"cac:Shipment/cac:TransportHandlingUnit/cac:ActualPackage/cbc:ID",
namespaces=ns,
)
package_type_xpath = line.xpath(
"cac:Shipment/cac:TransportHandlingUnit/cbc:TransportHandlingUnitTypeCode",
namespaces=ns,
)
package_weight_xpath = line.xpath(
"cac:Shipment/cac:GrossWeightMeasure/cbc:Measure", namespaces=ns
)
if package_id_xpath or package_type_xpath:
res_line["package"] = {

Check warning on line 145 in despatch_advice_import_ubl/wizard/despatch_advice_import.py

View check run for this annotation

Codecov / codecov/patch

despatch_advice_import_ubl/wizard/despatch_advice_import.py#L145

Added line #L145 was not covered by tests
"name": package_id_xpath[0].text if package_id_xpath else "",
"type": package_type_xpath[0].text if package_type_xpath else "",
"weight": package_weight_xpath[0].text if package_weight_xpath else "",
}

defaults = self.env.context.get("despatch_advice_import__default_vals", {}).get(
"lines", {}
)
Expand All @@ -141,9 +164,11 @@

vat_xpath = party_node.xpath("cac:PartyIdentification/cbc:ID", namespaces=ns)
partner_dict = {
"vat": vat_xpath[0].text
if vat_xpath and vat_xpath[0].attrib.get("schemeName").upper()
else False,
"vat": (
vat_xpath[0].text
if vat_xpath and vat_xpath[0].attrib.get("schemeName").upper()
else False
),
"name": partner_name_xpath[0].text,
}
address_xpath = party_node.xpath("cac:PostalAddress", namespaces=ns)
Expand Down
Loading