mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 00:14:50 +00:00
Merge pull request #44193 from frappe/mergify/bp/version-15-hotfix/pr-44134
fix: set debit in transaction currency in GL Entry (backport #44134)
This commit is contained in:
@@ -1146,6 +1146,12 @@ class PaymentEntry(AccountsController):
|
|||||||
if self.payment_type in ("Receive", "Pay") and not self.get("party_account_field"):
|
if self.payment_type in ("Receive", "Pay") and not self.get("party_account_field"):
|
||||||
self.setup_party_account_field()
|
self.setup_party_account_field()
|
||||||
|
|
||||||
|
company_currency = erpnext.get_company_currency(self.company)
|
||||||
|
if self.paid_from_account_currency != company_currency:
|
||||||
|
self.currency = self.paid_from_account_currency
|
||||||
|
elif self.paid_to_account_currency != company_currency:
|
||||||
|
self.currency = self.paid_to_account_currency
|
||||||
|
|
||||||
gl_entries = []
|
gl_entries = []
|
||||||
self.add_party_gl_entries(gl_entries)
|
self.add_party_gl_entries(gl_entries)
|
||||||
self.add_bank_gl_entries(gl_entries)
|
self.add_bank_gl_entries(gl_entries)
|
||||||
@@ -1248,13 +1254,22 @@ class PaymentEntry(AccountsController):
|
|||||||
base_unallocated_amount = self.unallocated_amount * exchange_rate
|
base_unallocated_amount = self.unallocated_amount * exchange_rate
|
||||||
|
|
||||||
gle = party_gl_dict.copy()
|
gle = party_gl_dict.copy()
|
||||||
gle.update(
|
|
||||||
{
|
|
||||||
dr_or_cr + "_in_account_currency": self.unallocated_amount,
|
|
||||||
dr_or_cr: base_unallocated_amount,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
gle.update(
|
||||||
|
self.get_gl_dict(
|
||||||
|
{
|
||||||
|
"account": self.party_account,
|
||||||
|
"party_type": self.party_type,
|
||||||
|
"party": self.party,
|
||||||
|
"against": against_account,
|
||||||
|
"account_currency": self.party_account_currency,
|
||||||
|
"cost_center": self.cost_center,
|
||||||
|
dr_or_cr + "_in_account_currency": self.unallocated_amount,
|
||||||
|
dr_or_cr: base_unallocated_amount,
|
||||||
|
},
|
||||||
|
item=self,
|
||||||
|
)
|
||||||
|
)
|
||||||
if self.book_advance_payments_in_separate_party_account:
|
if self.book_advance_payments_in_separate_party_account:
|
||||||
gle.update(
|
gle.update(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -956,6 +956,53 @@ class TestPaymentEntry(FrappeTestCase):
|
|||||||
self.assertEqual(flt(expected_party_balance), party_balance)
|
self.assertEqual(flt(expected_party_balance), party_balance)
|
||||||
self.assertEqual(flt(expected_party_account_balance, 2), flt(party_account_balance, 2))
|
self.assertEqual(flt(expected_party_account_balance, 2), flt(party_account_balance, 2))
|
||||||
|
|
||||||
|
def test_gl_of_multi_currency_payment_transaction(self):
|
||||||
|
from erpnext.setup.doctype.currency_exchange.test_currency_exchange import (
|
||||||
|
save_new_records,
|
||||||
|
test_records,
|
||||||
|
)
|
||||||
|
|
||||||
|
save_new_records(test_records)
|
||||||
|
paid_from = create_account(
|
||||||
|
parent_account="Current Liabilities - _TC",
|
||||||
|
account_name="_Test Cash USD",
|
||||||
|
company="_Test Company",
|
||||||
|
account_type="Cash",
|
||||||
|
account_currency="USD",
|
||||||
|
)
|
||||||
|
payment_entry = create_payment_entry(
|
||||||
|
party="_Test Supplier USD",
|
||||||
|
paid_from=paid_from,
|
||||||
|
paid_to="_Test Payable USD - _TC",
|
||||||
|
paid_amount=100,
|
||||||
|
save=True,
|
||||||
|
)
|
||||||
|
payment_entry.source_exchange_rate = 84.4
|
||||||
|
payment_entry.target_exchange_rate = 84.4
|
||||||
|
payment_entry.save()
|
||||||
|
payment_entry = payment_entry.submit()
|
||||||
|
gle = qb.DocType("GL Entry")
|
||||||
|
gl_entries = (
|
||||||
|
qb.from_(gle)
|
||||||
|
.select(
|
||||||
|
gle.account,
|
||||||
|
gle.debit,
|
||||||
|
gle.credit,
|
||||||
|
gle.debit_in_account_currency,
|
||||||
|
gle.credit_in_account_currency,
|
||||||
|
gle.debit_in_transaction_currency,
|
||||||
|
gle.credit_in_transaction_currency,
|
||||||
|
)
|
||||||
|
.orderby(gle.account)
|
||||||
|
.where(gle.voucher_no == payment_entry.name)
|
||||||
|
.run()
|
||||||
|
)
|
||||||
|
expected_gl_entries = (
|
||||||
|
(paid_from, 0.0, 8440.0, 0.0, 100.0, 0.0, 100.0),
|
||||||
|
("_Test Payable USD - _TC", 8440.0, 0.0, 100.0, 0.0, 100.0, 0.0),
|
||||||
|
)
|
||||||
|
self.assertEqual(gl_entries, expected_gl_entries)
|
||||||
|
|
||||||
def test_multi_currency_payment_entry_with_taxes(self):
|
def test_multi_currency_payment_entry_with_taxes(self):
|
||||||
payment_entry = create_payment_entry(
|
payment_entry = create_payment_entry(
|
||||||
party="_Test Supplier USD", paid_to="_Test Payable USD - _TC", save=True
|
party="_Test Supplier USD", paid_to="_Test Payable USD - _TC", save=True
|
||||||
|
|||||||
Reference in New Issue
Block a user