[fix] Multi currency patch
This commit is contained in:
parent
7523429ded
commit
a8de61e24b
@ -10,7 +10,8 @@ def execute():
|
|||||||
"Journal Entry Account", "Sales Invoice", "Purchase Invoice", "Customer", "Supplier"):
|
"Journal Entry Account", "Sales Invoice", "Purchase Invoice", "Customer", "Supplier"):
|
||||||
frappe.reload_doctype(dt)
|
frappe.reload_doctype(dt)
|
||||||
|
|
||||||
for company in frappe.get_all("Company", fields=["name", "default_currency", "default_receivable_account"]):
|
company_list = frappe.get_all("Company", fields=["name", "default_currency", "default_receivable_account"])
|
||||||
|
for company in company_list:
|
||||||
|
|
||||||
# update currency in account and gl entry as per company currency
|
# update currency in account and gl entry as per company currency
|
||||||
frappe.db.sql("""update `tabAccount` set account_currency = %s
|
frappe.db.sql("""update `tabAccount` set account_currency = %s
|
||||||
@ -67,26 +68,36 @@ def execute():
|
|||||||
for dt in ("Customer", "Supplier"):
|
for dt in ("Customer", "Supplier"):
|
||||||
parties = frappe.get_all(dt)
|
parties = frappe.get_all(dt)
|
||||||
for p in parties:
|
for p in parties:
|
||||||
# Get party GL Entries
|
|
||||||
party_gle = frappe.db.get_value("GL Entry", {"party_type": dt, "party": p.name,
|
|
||||||
"company": company.name}, ["account", "account_currency"], as_dict=True)
|
|
||||||
|
|
||||||
party = frappe.get_doc(dt, p.name)
|
party = frappe.get_doc(dt, p.name)
|
||||||
|
|
||||||
|
for company in company_list:
|
||||||
|
# Get party GL Entries
|
||||||
|
party_gle = frappe.db.get_value("GL Entry", {"party_type": dt, "party": p.name,
|
||||||
|
"company": company.name}, ["account", "account_currency", "name"], as_dict=True)
|
||||||
|
|
||||||
# set party account currency
|
# set party account currency
|
||||||
if party_gle or not party.party_account_currency:
|
if party_gle:
|
||||||
|
party.party_account_currency = party_gle.account_currency
|
||||||
|
elif not party.party_account_currency:
|
||||||
party.party_account_currency = company.default_currency
|
party.party_account_currency = company.default_currency
|
||||||
|
|
||||||
# Add default receivable /payable account if not exists
|
# Add default receivable /payable account if not exists
|
||||||
# and currency is other than company currency
|
# and currency is other than company currency
|
||||||
|
party_accounts = []
|
||||||
if party.party_account_currency and party.party_account_currency != company.default_currency:
|
if party.party_account_currency and party.party_account_currency != company.default_currency:
|
||||||
party_account_exists = False
|
party_account_exists_for_company = False
|
||||||
for d in party.get("accounts"):
|
for d in party.get("accounts"):
|
||||||
if d.company == company.name:
|
if d.company == company.name:
|
||||||
party_account_exists = True
|
account_currency = frappe.db.get_value("Account", d.account, "account_currency")
|
||||||
|
if account_currency == party.party_account_currency:
|
||||||
|
party_accounts.append({
|
||||||
|
"company": d.company,
|
||||||
|
"account": d.account
|
||||||
|
})
|
||||||
|
party_account_exists_for_company = True
|
||||||
break
|
break
|
||||||
|
|
||||||
if not party_account_exists:
|
if not party_account_exists_for_company:
|
||||||
party_account = None
|
party_account = None
|
||||||
if party_gle:
|
if party_gle:
|
||||||
party_account = party_gle.account
|
party_account = party_gle.account
|
||||||
@ -97,10 +108,10 @@ def execute():
|
|||||||
party_account = company.default_receivable_account
|
party_account = company.default_receivable_account
|
||||||
|
|
||||||
if party_account:
|
if party_account:
|
||||||
party.append("accounts", {
|
party_accounts.append({
|
||||||
"company": company.name,
|
"company": company.name,
|
||||||
"account": party_account
|
"account": party_account
|
||||||
})
|
})
|
||||||
|
party.set("accounts", party_accounts)
|
||||||
party.flags.ignore_mandatory = True
|
party.flags.ignore_mandatory = True
|
||||||
party.save()
|
party.save()
|
||||||
Loading…
x
Reference in New Issue
Block a user