Skip to content

Commit

Permalink
fix: use correct recipient company (sendcloud)
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra committed Feb 7, 2024
1 parent d7fee48 commit 543b737
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
10 changes: 5 additions & 5 deletions erpnext_shipping/erpnext_shipping/doctype/sendcloud/sendcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ def get_available_services(self, delivery_address, shipment_parcel):
except Exception:
show_error_alert("fetching SendCloud prices")

def create_shipment(self, shipment, delivery_address, delivery_contact, service_info, shipment_parcel,
def create_shipment(self, shipment, delivery_company_name, delivery_address, delivery_contact, service_info, shipment_parcel,
description_of_content, value_of_goods):
# Create a transaction at SendCloud
if not self.enabled or not self.api_key or not self.api_secret:
return []

parcels = []
for i, parcel in enumerate(json.loads(shipment_parcel), start=1):
parcel_data = self.get_parcel_dict(shipment, parcel, i, delivery_address,
parcel_data = self.get_parcel_dict(shipment, parcel, i, delivery_company_name, delivery_address,
delivery_contact, service_info, description_of_content, value_of_goods)
parcels.append(parcel_data)

Expand Down Expand Up @@ -174,11 +174,11 @@ def get_carrier(self, carrier_name, post_or_get=None):
else:
return carrier_name.upper() if post_or_get=="get" else carrier_name.lower()

def get_parcel_dict(self, shipment, parcel, index, delivery_address, delivery_contact,
def get_parcel_dict(self, shipment, parcel, index, delivery_company_name, delivery_address, delivery_contact,
service_info, description_of_content, value_of_goods):
return {
'name': "{} {}".format(delivery_contact.first_name, delivery_contact.last_name),
'company_name': delivery_address.address_title,
'company_name': delivery_company_name or delivery_address.address_title,
'address': delivery_address.address_line1,
'address_2': delivery_address.address_line2 or '',
'city': delivery_address.city,
Expand All @@ -195,4 +195,4 @@ def get_parcel_dict(self, shipment, parcel, index, delivery_address, delivery_co
'external_reference': "{}-{}".format(shipment, index),
'weight': parcel.get('weight'),
'parcel_items': self.get_parcel_items(parcel, description_of_content, value_of_goods)
}
}
15 changes: 15 additions & 0 deletions erpnext_shipping/erpnext_shipping/shipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def create_shipment(shipment, pickup_from_type, delivery_to_type, pickup_address
shipment_info, pickup_contact, delivery_contact = None, None, None
pickup_address = get_address(pickup_address_name)
delivery_address = get_address(delivery_address_name)
delivery_company_name = get_delivery_company_name(shipment)

if pickup_from_type != 'Company':
pickup_contact = get_contact(pickup_contact_name)
Expand Down Expand Up @@ -127,6 +128,7 @@ def create_shipment(shipment, pickup_from_type, delivery_to_type, pickup_address
sendcloud = SendCloudUtils()
shipment_info = sendcloud.create_shipment(
shipment=shipment,
delivery_company_name=delivery_company_name,
delivery_address=delivery_address,
shipment_parcel=shipment_parcel,
description_of_content=description_of_content,
Expand All @@ -146,6 +148,19 @@ def create_shipment(shipment, pickup_from_type, delivery_to_type, pickup_address

return shipment_info


def get_delivery_company_name(shipment: str) -> str | None:
shipment_doc = frappe.get_doc('Shipment', shipment)
if shipment_doc.delivery_customer:
return frappe.db.get_value('Customer', shipment_doc.delivery_customer, 'customer_name')
if shipment_doc.delivery_supplier:
return frappe.db.get_value('Supplier', shipment_doc.delivery_supplier, 'supplier_name')
if shipment_doc.delivery_company:
return frappe.db.get_value('Company', shipment_doc.delivery_company, 'company_name')

return None


@frappe.whitelist()
def print_shipping_label(service_provider, shipment_id):
if service_provider == LETMESHIP_PROVIDER:
Expand Down

0 comments on commit 543b737

Please sign in to comment.