fix: Expense account currency validation in Landed Cost voucher (#21073)
* fix: Expense account currency validation in Landed Cost voucher
* fix: Remove unused imports
diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py
index d18f8e5..163ef72 100644
--- a/erpnext/controllers/queries.py
+++ b/erpnext/controllers/queries.py
@@ -3,6 +3,7 @@
from __future__ import unicode_literals
import frappe
+import erpnext
from frappe.desk.reportview import get_match_cond, get_filters_cond
from frappe.utils import nowdate, getdate
from collections import defaultdict
@@ -129,23 +130,26 @@
})
def tax_account_query(doctype, txt, searchfield, start, page_len, filters):
+ company_currency = erpnext.get_company_currency(filters.get('company'))
+
tax_accounts = frappe.db.sql("""select name, parent_account from tabAccount
where tabAccount.docstatus!=2
and account_type in (%s)
and is_group = 0
and company = %s
+ and account_currency = %s
and `%s` LIKE %s
order by idx desc, name
limit %s, %s""" %
- (", ".join(['%s']*len(filters.get("account_type"))), "%s", searchfield, "%s", "%s", "%s"),
- tuple(filters.get("account_type") + [filters.get("company"), "%%%s%%" % txt,
+ (", ".join(['%s']*len(filters.get("account_type"))), "%s", "%s", searchfield, "%s", "%s", "%s"),
+ tuple(filters.get("account_type") + [filters.get("company"), company_currency, "%%%s%%" % txt,
start, page_len]))
if not tax_accounts:
tax_accounts = frappe.db.sql("""select name, parent_account from tabAccount
where tabAccount.docstatus!=2 and is_group = 0
- and company = %s and `%s` LIKE %s limit %s, %s"""
- % ("%s", searchfield, "%s", "%s", "%s"),
- (filters.get("company"), "%%%s%%" % txt, start, page_len))
+ and company = %s and account_currency = %s and `%s` LIKE %s limit %s, %s""" #nosec
+ % ("%s", "%s", searchfield, "%s", "%s", "%s"),
+ (filters.get("company"), company_currency, "%%%s%%" % txt, start, page_len))
return tax_accounts
diff --git a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py
index d97b699..5ad0e13 100644
--- a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py
+++ b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py
@@ -8,6 +8,7 @@
from frappe.model.meta import get_field_precision
from frappe.model.document import Document
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
+from erpnext.accounts.doctype.account.account import get_account_currency
class LandedCostVoucher(Document):
def get_items_from_purchase_receipts(self):
@@ -43,6 +44,7 @@
else:
self.validate_applicable_charges_for_item()
self.validate_purchase_receipts()
+ self.validate_expense_accounts()
self.set_total_taxes_and_charges()
def check_mandatory(self):
@@ -71,6 +73,14 @@
frappe.throw(_("Row {0}: Cost center is required for an item {1}")
.format(item.idx, item.item_code))
+ def validate_expense_accounts(self):
+ company_currency = erpnext.get_company_currency(self.company)
+ for account in self.taxes:
+ if get_account_currency(account.expense_account) != company_currency:
+ frappe.throw(msg=_(""" Row {0}: Expense account currency should be same as company's default currency.
+ Please select expense account with account currency as {1}""")
+ .format(account.idx, frappe.bold(company_currency)), title=_("Invalid Account Currency"))
+
def set_total_taxes_and_charges(self):
self.total_taxes_and_charges = sum([flt(d.amount) for d in self.get("taxes")])