Skip to content

Commit

Permalink
[FIX] Manage case when we got only 1 file from dpd
Browse files Browse the repository at this point in the history
In legacy mode, we always had 1 label + 1 summary file. With new BIC3 mode, the summary file is gone
  • Loading branch information
florian-dacosta committed May 15, 2023
1 parent 3552624 commit 64992a4
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions roulier/carriers/dpd_fr_soap/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ def decode(self, response, input_payload):
xml, "CreateShipmentWithLabels%sResult" % ("" if is_legacy else "Bc")
).getchildren()

label_file, summary_file = files.getchildren()

if is_legacy:
shipment = shipments.getchildren()[0]
parcel_field = "parcelnumber"
Expand All @@ -31,23 +29,32 @@ def decode(self, response, input_payload):
parcel_field = "BarcodeId"
barcode_field = "BarCode"

parcel = {
"id": 1,
"reference": self._get_parcel_number(input_payload)
or getattr(shipment, parcel_field).text,
"tracking": {
"number": getattr(shipment, barcode_field).text,
"url": "",
"partner": "",
},
"label": { # same as main label
"data": label_file.label.text,
"name": "label 1",
"type": output_format,
},
}
annexes = [
{"data": summary_file.label.text, "name": "Summary", "type": output_format}
]
self.result["parcels"].append(parcel)
self.result["annexes"] += annexes
annexes = []
for dpdfile in files.getchildren():
# label file : EPRINT legacy type, BIC3 geolabel type
if dpdfile.type.text in ("EPRINT", "BIC3"):
parcel = {
"id": 1,
"reference": self._get_parcel_number(input_payload)
or getattr(shipment, parcel_field).text,
"tracking": {
"number": getattr(shipment, barcode_field).text,
"url": "",
"partner": "",
},
"label": { # same as main label
"data": dpdfile.label.text,
"name": "label 1",
"type": output_format,
},
}
self.result["parcels"].append(parcel)
# summary file (EPRINTATTACHMENT) or any other file but not supported yet.
else:
self.result["annexes"].append(
{
"data": dpdfile.label.text,
"name": "Summary",
"type": output_format,
}
)

0 comments on commit 64992a4

Please sign in to comment.