From 1bd9c471a4802e3386ca196dbfc743da62759672 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Wed, 7 Feb 2024 19:47:06 +0100 Subject: [PATCH] fix: use correct recipient company (letmeship) --- .../doctype/letmeship/letmeship.py | 16 ++++++++-------- erpnext_shipping/erpnext_shipping/shipping.py | 1 + 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/erpnext_shipping/erpnext_shipping/doctype/letmeship/letmeship.py b/erpnext_shipping/erpnext_shipping/doctype/letmeship/letmeship.py index 9fa6332..b95cb03 100644 --- a/erpnext_shipping/erpnext_shipping/doctype/letmeship/letmeship.py +++ b/erpnext_shipping/erpnext_shipping/doctype/letmeship/letmeship.py @@ -33,8 +33,8 @@ def get_available_services(self, delivery_to_type, pickup_address, return [] self.set_letmeship_specific_fields(pickup_contact, delivery_contact) - pickup_address.address_title = self.trim_address(pickup_address) - delivery_address.address_title = self.trim_address(delivery_address) + pickup_address.address_title = self.first_30_chars(pickup_address.address_title) + delivery_address.address_title = self.first_30_chars(delivery_address.address_title) parcel_list = self.get_parcel_list(json.loads(shipment_parcel), description_of_content) url = 'https://api.letmeship.com/v1/available' @@ -76,15 +76,15 @@ def get_available_services(self, delivery_to_type, pickup_address, return [] - def create_shipment(self, pickup_address, delivery_address, shipment_parcel, description_of_content, + def create_shipment(self, pickup_address, delivery_company_name, delivery_address, shipment_parcel, description_of_content, pickup_date, value_of_goods, service_info, pickup_contact=None, delivery_contact=None): # Create a transaction at LetMeShip if not self.enabled or not self.api_id or not self.api_password: return [] self.set_letmeship_specific_fields(pickup_contact, delivery_contact) - pickup_address.address_title = self.trim_address(pickup_address) - delivery_address.address_title = self.trim_address(delivery_address) + pickup_address.address_title = self.first_30_chars(pickup_address.address_title) + delivery_address.address_title = self.first_30_chars(delivery_company_name or delivery_address.address_title) parcel_list = self.get_parcel_list(json.loads(shipment_parcel), description_of_content) url = 'https://api.letmeship.com/v1/shipments' @@ -253,10 +253,10 @@ def generate_payload(self, pickup_address, pickup_contact, delivery_address, del payload['labelEmail'] = True return payload - def trim_address(self, address): + def first_30_chars(self, address_title: str): # LetMeShip has a limit of 30 characters for Company field - if len(address.address_title) > 30: - return address.address_title[:30] + if len(address_title) > 30: + return address_title[:30] def get_service_dict(self, response): """Returns a dictionary with service info.""" diff --git a/erpnext_shipping/erpnext_shipping/shipping.py b/erpnext_shipping/erpnext_shipping/shipping.py index d94fdb7..dd9214c 100644 --- a/erpnext_shipping/erpnext_shipping/shipping.py +++ b/erpnext_shipping/erpnext_shipping/shipping.py @@ -100,6 +100,7 @@ def create_shipment(shipment, pickup_from_type, delivery_to_type, pickup_address letmeship = LetMeShipUtils() shipment_info = letmeship.create_shipment( pickup_address=pickup_address, + delivery_company_name=delivery_company_name, delivery_address=delivery_address, shipment_parcel=shipment_parcel, description_of_content=description_of_content,