From 39539f14ce5f851a9316527d0c21328802ad4003 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 14 Apr 2015 13:07:28 +0530 Subject: [PATCH] [patch-fix] make_email_accounts --- erpnext/patches/v4_4/make_email_accounts.py | 44 +++++++++------------ 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/erpnext/patches/v4_4/make_email_accounts.py b/erpnext/patches/v4_4/make_email_accounts.py index 528fe0812a3..dd74fc97cd7 100644 --- a/erpnext/patches/v4_4/make_email_accounts.py +++ b/erpnext/patches/v4_4/make_email_accounts.py @@ -46,20 +46,7 @@ def execute(): account.enable_outgoing = 0 account.append_to = "Issue" - try: - account.insert() - except frappe.NameError, e: - if e.args[0]=="Email Account": - existing_account = frappe.get_doc("Email Account", e.args[1]) - for key, value in account.as_dict().items(): - if not existing_account.get(key) and value and key not in default_fields: - existing_account.set(key, value) - - existing_account.save() - - else: - raise - + insert_or_update(account) # sales, jobs for doctype in ("Sales Email Settings", "Jobs Email Settings"): @@ -80,20 +67,25 @@ def execute(): account.enable_outgoing = 0 account.append_to = "Lead" if doctype=="Sales Email Settings" else "Job Applicant" - try: - account.insert() - except frappe.NameError, e: - if e.args[0]=="Email Account": - existing_account = frappe.get_doc("Email Account", e.args[1]) - for key, value in account.as_dict().items(): - if not existing_account.get(key) and value and key not in default_fields: - existing_account.set(key, value) - - existing_account.save() - else: - raise + insert_or_update(account) for doctype in ("Outgoing Email Settings", "Support Email Settings", "Sales Email Settings", "Jobs Email Settings"): frappe.delete_doc("DocType", doctype) +def insert_or_update(account): + try: + account.insert() + except frappe.NameError, e: + if e.args[0]=="Email Account": + existing_account = frappe.get_doc("Email Account", e.args[0]) + for key, value in account.as_dict().items(): + if not existing_account.get(key) and value \ + and key not in default_fields \ + and key != "__islocal": + existing_account.set(key, value) + + existing_account.save() + else: + raise +