From e0f175638b3b8f693542478f7804505086f3a1cf Mon Sep 17 00:00:00 2001 From: David Date: Thu, 4 Jul 2024 09:42:02 +0200 Subject: [PATCH] [FIX] delivery_dhl_parcel: show full name If we just show the partner's name there will be cases where we'll be losing the most important info which is the main organization where the shipping is sent. TT49966 --- delivery_dhl_parcel/models/delivery_carrier.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/delivery_dhl_parcel/models/delivery_carrier.py b/delivery_dhl_parcel/models/delivery_carrier.py index 8ddd48aad1..78ec2de195 100644 --- a/delivery_dhl_parcel/models/delivery_carrier.py +++ b/delivery_dhl_parcel/models/delivery_carrier.py @@ -73,8 +73,20 @@ def _prepare_dhl_parcel_address_info(self, partner): address = partner.street or "" if partner.street2: address += " " + partner.street2 + partner_name = partner.name + # We have a limit of 40 chars, so we'll try to allocate as much space possible + # for both parent an contact name, trying to use all the available space if + # possible and otherwise, cutting it to 19 chars max (letting 2 chars for + # the separation of both names) + if partner.parent_id: + max_parent_length = min( + len(partner.parent_id.name), 19 + max(19 - len(partner_name), 0) + ) + partner_name = ( + f"{partner.parent_id.name[:max_parent_length]}, {partner_name}" + ) return { - "Name": partner.name or partner.parent_id.name or "", + "Name": partner_name[:40], "Address": address[:40], "City": partner.city or "", "PostalCode": partner.zip or "",