fix: combine jv entries for rate revaluation

This commit is contained in:
Gursheen Anand 2023-11-06 16:45:56 +05:30
parent 35d92abe73
commit 3d00d74fed

View File

@ -467,16 +467,6 @@ class ExchangeRateRevaluation(Document):
else "credit_in_account_currency"
)
balance_in_account_currency = flt(
abs(d.get("balance_in_account_currency")), d.precision("balance_in_account_currency")
)
difference_amount = (
flt(d.get("new_exchange_rate"), d.precision("new_exchange_rate")) * balance_in_account_currency
)
difference_amount -= (
flt(d.get("current_exchange_rate"), d.precision("current_exchange_rate"))
* balance_in_account_currency
)
journal_entry_accounts.append(
{
"account": d.get("account"),
@ -513,26 +503,28 @@ class ExchangeRateRevaluation(Document):
"reference_name": self.name,
}
)
journal_entry_accounts.append(
{
"party_type": d.get("party_type"),
"party": d.get("party"),
"account": unrealized_exchange_gain_loss_account,
"balance": get_balance_on(unrealized_exchange_gain_loss_account),
"debit_in_account_currency": abs(difference_amount) if difference_amount < 0 else 0,
"credit_in_account_currency": difference_amount if difference_amount > 0 else 0,
"cost_center": erpnext.get_default_cost_center(self.company),
"exchange_rate": 1,
"reference_type": "Exchange Rate Revaluation",
"reference_name": self.name,
}
)
journal_entry.set("accounts", journal_entry_accounts)
journal_entry.set_amounts_in_company_currency()
journal_entry.set_total_debit_credit()
self.gain_loss_unbooked += journal_entry.difference - self.gain_loss_unbooked
journal_entry.append(
"accounts",
{
"account": unrealized_exchange_gain_loss_account,
"balance": get_balance_on(unrealized_exchange_gain_loss_account),
"debit_in_account_currency": abs(self.gain_loss_unbooked)
if self.gain_loss_unbooked < 0
else 0,
"credit_in_account_currency": self.gain_loss_unbooked if self.gain_loss_unbooked > 0 else 0,
"cost_center": erpnext.get_default_cost_center(self.company),
"exchange_rate": 1,
"reference_type": "Exchange Rate Revaluation",
"reference_name": self.name,
},
)
journal_entry.set_amounts_in_company_currency()
journal_entry.set_total_debit_credit()
journal_entry.save()