From aa015902d5d536ceefc5a142d58b30f64403d7a6 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 16 Oct 2015 13:08:33 +0530 Subject: [PATCH] Validate currency of default receivable/payable accounts --- .../accounts/doctype/purchase_invoice/purchase_invoice.py | 2 +- erpnext/accounts/doctype/sales_invoice/sales_invoice.py | 2 +- erpnext/accounts/party.py | 6 ++---- erpnext/accounts/utils.py | 4 +++- erpnext/public/js/controllers/transaction.js | 3 ++- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index d4a5fa179b..2e34980352 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -76,7 +76,7 @@ class PurchaseInvoice(BuyingController): def get_advances(self): if not self.is_return: super(PurchaseInvoice, self).get_advances(self.credit_to, "Supplier", self.supplier, - "Purchase Invoice Advance", "advances", "debit", "purchase_order") + "Purchase Invoice Advance", "advances", "debit_in_account_currency", "purchase_order") def check_active_purchase_items(self): for d in self.get('items'): diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 940f754262..a349e2fe4b 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -256,7 +256,7 @@ class SalesInvoice(SellingController): def get_advances(self): if not self.is_return: super(SalesInvoice, self).get_advances(self.debit_to, "Customer", self.customer, - "Sales Invoice Advance", "advances", "credit", "sales_order") + "Sales Invoice Advance", "advances", "credit_in_account_currency", "sales_order") def get_company_abbr(self): return frappe.db.sql("select abbr from tabCompany where name=%s", self.company)[0][0] diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index fa653359aa..516608ff0e 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -225,10 +225,8 @@ def validate_party_accounts(doc): party_account_currency = frappe.db.get_value("Account", account.account, "account_currency") existing_gle_currency = get_party_gle_currency(doc.doctype, doc.name, account.company) - if party_account_currency != existing_gle_currency: - frappe.throw(_("Accounting Entry against company: {0} can only be made in currency: {1}, please check default {2} account") - .format(account.company, existing_gle_currency, - "receivable" if doc.doctype=="Customer" else "payable")) + if existing_gle_currency and party_account_currency != existing_gle_currency: + frappe.throw(_("Accounting entries have already been made in currency {0} for company {1}. Please select a receivable or payable account with currency {0}.").format(existing_gle_currency, account.company)) @frappe.whitelist() def get_due_date(posting_date, party_type, party, company): diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index ffb8a4c3dc..88b1ed4c6c 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -211,7 +211,8 @@ def update_against_doc(d, jv_obj): if d['allocated_amt'] < d['unadjusted_amt']: jvd = frappe.db.sql(""" - select cost_center, balance, against_account, is_advance, account_type, exchange_rate + select cost_center, balance, against_account, is_advance, + account_type, exchange_rate, account_currency from `tabJournal Entry Account` where name = %s """, d['voucher_detail_no'], as_dict=True) @@ -222,6 +223,7 @@ def update_against_doc(d, jv_obj): ch = jv_obj.append("accounts") ch.account = d['account'] ch.account_type = jvd[0]['account_type'] + ch.account_currency = jvd[0]['account_currency'] ch.exchange_rate = jvd[0]['exchange_rate'] ch.party_type = d["party_type"] ch.party = d["party"] diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 7f2cee760a..08d4f32b68 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -495,7 +495,8 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ } if(this.frm.fields_dict["advances"]) { - setup_field_label_map(["advance_amount", "allocated_amount"], company_currency, "advances"); + setup_field_label_map(["advance_amount", "allocated_amount"], + this.frm.doc.party_account_currency, "advances"); } // toggle columns