Skip to content

Commit

Permalink
refactor: handle exceptions when updating addresses (#22307)
Browse files Browse the repository at this point in the history
* refactor: handle exceptions when updating addresses

* refactor: fold common statements in a loop
  • Loading branch information
scmmishra committed Jun 18, 2020
1 parent 96100e9 commit 34d2bfb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions erpnext/erpnext_integrations/connectors/woocommerce_connection.py
Expand Up @@ -73,10 +73,16 @@ def link_customer_and_address(raw_billing_data, raw_shipping_data, customer_name

if customer_exists:
frappe.rename_doc("Customer", old_name, customer_name)
billing_address = frappe.get_doc("Address", {"woocommerce_email": customer_woo_com_email, "address_type": "Billing"})
shipping_address = frappe.get_doc("Address", {"woocommerce_email": customer_woo_com_email, "address_type": "Shipping"})
rename_address(billing_address, customer)
rename_address(shipping_address, customer)
for address_type in ("Billing", "Shipping",):
try:
address = frappe.get_doc("Address", {"woocommerce_email": customer_woo_com_email, "address_type": address_type})
rename_address(address, customer)
except (
frappe.DoesNotExistError,
frappe.DuplicateEntryError,
frappe.ValidationError,
):
pass
else:
create_address(raw_billing_data, customer, "Billing")
create_address(raw_shipping_data, customer, "Shipping")
Expand Down

0 comments on commit 34d2bfb

Please sign in to comment.