Fixes for customer / supplier renaming
This commit is contained in:
@@ -325,32 +325,38 @@ def get_actual_expense(args):
|
||||
and fiscal_year='%(fiscal_year)s' and company='%(company)s' %(condition)s
|
||||
""" % (args))[0][0]
|
||||
|
||||
def rename_account_for(dt, olddn, newdn, merge, company):
|
||||
old_account = get_account_for(dt, olddn)
|
||||
if old_account:
|
||||
new_account = None
|
||||
if not merge:
|
||||
if old_account == add_abbr_if_missing(olddn, company):
|
||||
new_account = frappe.rename_doc("Account", old_account, newdn)
|
||||
else:
|
||||
existing_new_account = get_account_for(dt, newdn)
|
||||
new_account = frappe.rename_doc("Account", old_account,
|
||||
existing_new_account or newdn, merge=True if existing_new_account else False)
|
||||
def rename_account_for(dt, olddn, newdn, merge, company=None):
|
||||
if not company:
|
||||
companies = [d[0] for d in frappe.db.sql("select name from tabCompany")]
|
||||
else:
|
||||
companies = [company]
|
||||
|
||||
frappe.db.set_value("Account", new_account or old_account, "master_name", newdn)
|
||||
for company in companies:
|
||||
old_account = get_account_for(dt, olddn, company)
|
||||
if old_account:
|
||||
new_account = None
|
||||
if not merge:
|
||||
if old_account == add_abbr_if_missing(olddn, company):
|
||||
new_account = frappe.rename_doc("Account", old_account, newdn)
|
||||
else:
|
||||
existing_new_account = get_account_for(dt, newdn, company)
|
||||
new_account = frappe.rename_doc("Account", old_account,
|
||||
existing_new_account or newdn, merge=True if existing_new_account else False)
|
||||
|
||||
frappe.db.set_value("Account", new_account or old_account, "master_name", newdn)
|
||||
|
||||
def add_abbr_if_missing(dn, company):
|
||||
from erpnext.setup.doctype.company.company import get_name_with_abbr
|
||||
return get_name_with_abbr(dn, company)
|
||||
|
||||
def get_account_for(account_for_doctype, account_for):
|
||||
def get_account_for(account_for_doctype, account_for, company):
|
||||
if account_for_doctype in ["Customer", "Supplier"]:
|
||||
account_for_field = "master_type"
|
||||
elif account_for_doctype == "Warehouse":
|
||||
account_for_field = "account_type"
|
||||
|
||||
return frappe.db.get_value("Account", {account_for_field: account_for_doctype,
|
||||
"master_name": account_for})
|
||||
"master_name": account_for, "company": company})
|
||||
|
||||
def get_currency_precision(currency=None):
|
||||
if not currency:
|
||||
|
||||
Reference in New Issue
Block a user