From 4a6bbf9b723c12753bcc1ce48377ec578253bd83 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 23 Feb 2016 20:01:04 +0530 Subject: [PATCH] [fixes] added filters company and currency to get account, removed account name wise comparison --- erpnext/accounts/utils.py | 20 +++++++++----------- erpnext/shopping_cart/cart.py | 6 +++--- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 53a1b6a0833..36ff1ab72c3 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -479,15 +479,13 @@ def get_outstanding_invoices(party_type, party, account, condition=None): return outstanding_invoices -def get_account(account_type=None, root_type=None, is_group=None, account_name=None): +def get_account(account_type=None, root_type=None, is_group=None, account_currency=None, company=None): """return account based on matching conditions""" - if account_name: - if not frappe.db.get_value("Account", {"account_name": account_name}): - return False - else: - return frappe.get_doc("Account", { - "account_type": account_type or '', - "root_type": root_type or '', - "is_group": is_group or 0, - "account_name": account_name or '' - }) \ No newline at end of file + return frappe.db.get_value("Account", { + "account_type": account_type or '', + "root_type": root_type or '', + "is_group": is_group or 0, + "account_currency": account_currency or frappe.defaults.get_defaults().currency, + "company": company or frappe.defaults.get_defaults().company + }, "name") + \ No newline at end of file diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py index b4df27dca25..012aaf7750a 100644 --- a/erpnext/shopping_cart/cart.py +++ b/erpnext/shopping_cart/cart.py @@ -329,7 +329,8 @@ def get_debtors_account(cart_settings): account_name = _("Debtors ({0})".format(payment_gateway_account_currency)) - debtors_account = get_account("Receivable", "Asset", is_group=0, account_name=account_name) + debtors_account = get_account("Receivable", "Asset", is_group=0,\ + account_currency=payment_gateway_account_currency, company=cart_settings.company) if not debtors_account: debtors_account = frappe.get_doc({ @@ -337,8 +338,7 @@ def get_debtors_account(cart_settings): "account_type": "Receivable", "root_type": "Asset", "is_group": 0, - "parent_account": get_account(root_type="Asset", is_group=1, \ - account_name=_("Accounts Receivable")).name, + "parent_account": get_account(root_type="Asset", is_group=1, company=cart_settings.company), "account_name": account_name, "currency": payment_gateway_account_currency }).insert(ignore_permissions=True)