Merge pull request #26916 from deepeshgarg007/party_account_currency_check
fix: Account currency validation for first transaction
This commit is contained in:
commit
b562168509
@ -78,6 +78,8 @@ class TestPeriodClosingVoucher(unittest.TestCase):
|
||||
expense_account="Cost of Goods Sold - TPC",
|
||||
rate=400,
|
||||
debit_to="Debtors - TPC",
|
||||
currency="USD",
|
||||
customer="_Test Customer USD",
|
||||
)
|
||||
create_sales_invoice(
|
||||
company=company,
|
||||
@ -86,6 +88,8 @@ class TestPeriodClosingVoucher(unittest.TestCase):
|
||||
expense_account="Cost of Goods Sold - TPC",
|
||||
rate=200,
|
||||
debit_to="Debtors - TPC",
|
||||
currency="USD",
|
||||
customer="_Test Customer USD",
|
||||
)
|
||||
|
||||
pcv = self.make_period_closing_voucher(submit=False)
|
||||
@ -119,14 +123,17 @@ class TestPeriodClosingVoucher(unittest.TestCase):
|
||||
surplus_account = create_account()
|
||||
cost_center = create_cost_center("Test Cost Center 1")
|
||||
|
||||
create_sales_invoice(
|
||||
si = create_sales_invoice(
|
||||
company=company,
|
||||
income_account="Sales - TPC",
|
||||
expense_account="Cost of Goods Sold - TPC",
|
||||
cost_center=cost_center,
|
||||
rate=400,
|
||||
debit_to="Debtors - TPC",
|
||||
currency="USD",
|
||||
customer="_Test Customer USD",
|
||||
)
|
||||
|
||||
jv = make_journal_entry(
|
||||
account1="Cash - TPC",
|
||||
account2="Sales - TPC",
|
||||
|
@ -752,7 +752,7 @@ class TestPricingRule(unittest.TestCase):
|
||||
title="_Test Pricing Rule with Min Qty - 2",
|
||||
)
|
||||
|
||||
si = create_sales_invoice(do_not_submit=True, customer="_Test Customer 1", qty=1, currency="USD")
|
||||
si = create_sales_invoice(do_not_submit=True, customer="_Test Customer 1", qty=1)
|
||||
item = si.items[0]
|
||||
item.stock_qty = 1
|
||||
si.save()
|
||||
|
@ -897,3 +897,18 @@ def get_default_contact(doctype, name):
|
||||
return None
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def add_party_account(party_type, party, company, account):
|
||||
doc = frappe.get_doc(party_type, party)
|
||||
account_exists = False
|
||||
for d in doc.get("accounts"):
|
||||
if d.account == account:
|
||||
account_exists = True
|
||||
|
||||
if not account_exists:
|
||||
accounts = {"company": company, "account": account}
|
||||
|
||||
doc.append("accounts", accounts)
|
||||
|
||||
doc.save()
|
||||
|
@ -34,6 +34,7 @@ from erpnext.accounts.doctype.pricing_rule.utils import (
|
||||
from erpnext.accounts.party import (
|
||||
get_party_account,
|
||||
get_party_account_currency,
|
||||
get_party_gle_currency,
|
||||
validate_party_frozen_disabled,
|
||||
)
|
||||
from erpnext.accounts.utils import get_account_currency, get_fiscal_years, validate_fiscal_year
|
||||
@ -168,6 +169,7 @@ class AccountsController(TransactionBase):
|
||||
|
||||
self.validate_party()
|
||||
self.validate_currency()
|
||||
self.validate_party_account_currency()
|
||||
|
||||
if self.doctype in ["Purchase Invoice", "Sales Invoice"]:
|
||||
pos_check_field = "is_pos" if self.doctype == "Sales Invoice" else "is_paid"
|
||||
@ -1447,6 +1449,27 @@ class AccountsController(TransactionBase):
|
||||
# at quotation / sales order level and we shouldn't stop someone
|
||||
# from creating a sales invoice if sales order is already created
|
||||
|
||||
def validate_party_account_currency(self):
|
||||
if self.doctype not in ("Sales Invoice", "Purchase Invoice"):
|
||||
return
|
||||
|
||||
if self.is_opening == "Yes":
|
||||
return
|
||||
|
||||
party_type, party = self.get_party()
|
||||
party_gle_currency = get_party_gle_currency(party_type, party, self.company)
|
||||
party_account = (
|
||||
self.get("debit_to") if self.doctype == "Sales Invoice" else self.get("credit_to")
|
||||
)
|
||||
party_account_currency = get_account_currency(party_account)
|
||||
|
||||
if not party_gle_currency and (party_account_currency != self.currency):
|
||||
frappe.throw(
|
||||
_("Party Account {0} currency and document currency should be same").format(
|
||||
frappe.bold(party_account)
|
||||
)
|
||||
)
|
||||
|
||||
def delink_advance_entries(self, linked_doc_name):
|
||||
total_allocated_amount = 0
|
||||
for adv in self.advances:
|
||||
|
@ -1285,6 +1285,14 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import (
|
||||
make_purchase_invoice as create_purchase_invoice,
|
||||
)
|
||||
from erpnext.accounts.party import add_party_account
|
||||
|
||||
add_party_account(
|
||||
"Supplier",
|
||||
"_Test Supplier USD",
|
||||
"_Test Company with perpetual inventory",
|
||||
"_Test Payable USD - TCP1",
|
||||
)
|
||||
|
||||
pi = create_purchase_invoice(
|
||||
company="_Test Company with perpetual inventory",
|
||||
@ -1293,6 +1301,7 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
expense_account="_Test Account Cost for Goods Sold - TCP1",
|
||||
currency="USD",
|
||||
conversion_rate=70,
|
||||
supplier="_Test Supplier USD",
|
||||
)
|
||||
|
||||
pr = create_purchase_receipt(pi.name)
|
||||
|
Loading…
Reference in New Issue
Block a user