refactor: handle exceptions when updating addresses (#22307)

* refactor: handle exceptions when updating addresses

* refactor: fold common statements in a loop
This commit is contained in:
Shivam Mishra 2020-06-18 09:58:55 +00:00 committed by GitHub
parent 96100e9507
commit 34d2bfbb3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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")