Skip to content

Commit

Permalink
fix: incorrect paid_amount and exchange rate in PE
Browse files Browse the repository at this point in the history
If Company master has no default cash or bank account set but Party has
default company bank account set. In this case, paid_amount and
conversion rate are not calculated correctly
  • Loading branch information
ruthra-kumar committed Apr 30, 2023
1 parent 04902e1 commit 1233553
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions erpnext/accounts/doctype/payment_entry/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,13 @@ def get_payment_entry(
# bank or cash
bank = get_bank_cash_account(doc, bank_account)

# if default bank or cash account is not set in company master and party has default company bank account, fetch it
if party_type in ["Customer", "Supplier"] and not bank:
party_bank_account = get_party_bank_account(party_type, doc.get(scrub(party_type)))
if party_bank_account:
account = frappe.db.get_value("Bank Account", party_bank_account, "account")
bank = get_bank_cash_account(doc, account)

paid_amount, received_amount = set_paid_amount_and_received_amount(
dt, party_account_currency, bank, outstanding_amount, payment_type, bank_amount, doc
)
Expand Down Expand Up @@ -1928,19 +1935,27 @@ def set_paid_amount_and_received_amount(
paid_amount = received_amount = 0
if party_account_currency == bank.account_currency:
paid_amount = received_amount = abs(outstanding_amount)
elif payment_type == "Receive":
paid_amount = abs(outstanding_amount)
if bank_amount:
received_amount = bank_amount
else:
received_amount = paid_amount * doc.get("conversion_rate", 1)
else:
received_amount = abs(outstanding_amount)
if bank_amount:
paid_amount = bank_amount
company_currency = frappe.get_cached_value("Company", doc.get("company"), "default_currency")
if payment_type == "Receive":
paid_amount = abs(outstanding_amount)
if bank_amount:
received_amount = bank_amount
else:
if company_currency != bank.account_currency:
received_amount = paid_amount / doc.get("conversion_rate", 1)
else:
received_amount = paid_amount * doc.get("conversion_rate", 1)
else:
# if party account currency and bank currency is different then populate paid amount as well
paid_amount = received_amount * doc.get("conversion_rate", 1)
received_amount = abs(outstanding_amount)
if bank_amount:
paid_amount = bank_amount
else:
if company_currency != bank.account_currency:
paid_amount = received_amount / doc.get("conversion_rate", 1)
else:
# if party account currency and bank currency is different then populate paid amount as well
paid_amount = received_amount * doc.get("conversion_rate", 1)

return paid_amount, received_amount

Expand Down

0 comments on commit 1233553

Please sign in to comment.