Skip to content

Commit

Permalink
Merge pull request #35186 from ruthra-kumar/child_account_should_inhe…
Browse files Browse the repository at this point in the history
…rit_parent_account_currency

fix: child acc will inherit acc currency if explicitly specified
  • Loading branch information
ruthra-kumar authored May 8, 2023
2 parents ecc80a8 + f6ea8fd commit 34a5f24
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
9 changes: 7 additions & 2 deletions erpnext/accounts/doctype/account/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,11 @@ def validate_balance_must_be_debit_or_credit(self):
)

def validate_account_currency(self):
self.currency_explicitly_specified = True

if not self.account_currency:
self.account_currency = frappe.get_cached_value("Company", self.company, "default_currency")
self.currency_explicitly_specified = False

gl_currency = frappe.db.get_value("GL Entry", {"account": self.name}, "account_currency")

Expand Down Expand Up @@ -251,8 +254,10 @@ def create_account_for_child_company(self, parent_acc_name_map, descendants, par
{
"company": company,
# parent account's currency should be passed down to child account's curreny
# if it is None, it picks it up from default company currency, which might be unintended
"account_currency": erpnext.get_company_currency(company),
# if currency explicitly specified by user, child will inherit. else, default currency will be used.
"account_currency": self.account_currency
if self.currency_explicitly_specified
else erpnext.get_company_currency(company),
"parent_account": parent_acc_name_map[company],
}
)
Expand Down
55 changes: 55 additions & 0 deletions erpnext/accounts/doctype/account/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import unittest

import frappe
from frappe.test_runner import make_test_records

from erpnext.accounts.doctype.account.account import merge_account, update_account_number
from erpnext.stock import get_company_default_inventory_account, get_warehouse_account

test_dependencies = ["Company"]


class TestAccount(unittest.TestCase):
def test_rename_account(self):
Expand Down Expand Up @@ -188,6 +191,58 @@ def test_account_rename_sync(self):
frappe.delete_doc("Account", "1234 - Test Rename Sync Account - _TC4")
frappe.delete_doc("Account", "1234 - Test Rename Sync Account - _TC5")

def test_account_currency_sync(self):
"""
In a parent->child company setup, child should inherit parent account currency if explicitly specified.
"""

make_test_records("Company")

frappe.local.flags.pop("ignore_root_company_validation", None)

def create_bank_account():
acc = frappe.new_doc("Account")
acc.account_name = "_Test Bank JPY"

acc.parent_account = "Temporary Accounts - _TC6"
acc.company = "_Test Company 6"
return acc

acc = create_bank_account()
# Explicitly set currency
acc.account_currency = "JPY"
acc.insert()
self.assertTrue(
frappe.db.exists(
{
"doctype": "Account",
"account_name": "_Test Bank JPY",
"account_currency": "JPY",
"company": "_Test Company 7",
}
)
)

frappe.delete_doc("Account", "_Test Bank JPY - _TC6")
frappe.delete_doc("Account", "_Test Bank JPY - _TC7")

acc = create_bank_account()
# default currency is used
acc.insert()
self.assertTrue(
frappe.db.exists(
{
"doctype": "Account",
"account_name": "_Test Bank JPY",
"account_currency": "USD",
"company": "_Test Company 7",
}
)
)

frappe.delete_doc("Account", "_Test Bank JPY - _TC6")
frappe.delete_doc("Account", "_Test Bank JPY - _TC7")

def test_child_company_account_rename_sync(self):
frappe.local.flags.pop("ignore_root_company_validation", None)

Expand Down
25 changes: 25 additions & 0 deletions erpnext/setup/doctype/company/test_records.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,30 @@
"chart_of_accounts": "Standard",
"enable_perpetual_inventory": 1,
"default_holiday_list": "_Test Holiday List"
},
{
"abbr": "_TC6",
"company_name": "_Test Company 6",
"is_group": 1,
"country": "India",
"default_currency": "INR",
"doctype": "Company",
"domain": "Manufacturing",
"chart_of_accounts": "Standard",
"default_holiday_list": "_Test Holiday List",
"enable_perpetual_inventory": 0
},
{
"abbr": "_TC7",
"company_name": "_Test Company 7",
"parent_company": "_Test Company 6",
"is_group": 1,
"country": "United States",
"default_currency": "USD",
"doctype": "Company",
"domain": "Manufacturing",
"chart_of_accounts": "Standard",
"default_holiday_list": "_Test Holiday List",
"enable_perpetual_inventory": 0
}
]

0 comments on commit 34a5f24

Please sign in to comment.