Skip to content

Commit

Permalink
[patch-fix] make_email_accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
rmehta committed Apr 14, 2015
1 parent 2c78796 commit 39539f1
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions erpnext/patches/v4_4/make_email_accounts.py
Expand Up @@ -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"):
Expand All @@ -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

0 comments on commit 39539f1

Please sign in to comment.