Skip to content

Commit

Permalink
fix: GL values in transaction currency via JV (#38914)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepeshgarg007 authored Dec 31, 2023
1 parent 877cc72 commit 3f9693b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
24 changes: 24 additions & 0 deletions erpnext/accounts/doctype/journal_entry/journal_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,10 @@ def set_total_amount(self, amt, currency):

def build_gl_map(self):
gl_map = []
conversion_rate_map = self.get_conversion_rate_map()
transaction_currency_map = self.get_transaction_currency_map()
company_currency = erpnext.get_company_currency(self.company)

self.get_against_accounts()
for d in self.get("accounts"):
if d.debit or d.credit or (self.voucher_type == "Exchange Gain Or Loss"):
Expand Down Expand Up @@ -1060,6 +1064,12 @@ def build_gl_map(self):
"cost_center": d.cost_center,
"project": d.project,
"finance_book": self.finance_book,
"conversion_rate": conversion_rate_map.get(d.against_account_link, 1)
if d.account_currency == company_currency
else 1,
"currency": transaction_currency_map.get(d.against_account_link, d.account_currency)
if d.account_currency == company_currency
else d.account_currency,
},
item=d,
)
Expand Down Expand Up @@ -1109,6 +1119,20 @@ def build_gl_map(self):

return gl_map

def get_transaction_currency_map(self):
transaction_currency_map = {}
for account in self.get("accounts"):
transaction_currency_map.setdefault(account.party or account.account, account.account_currency)

return transaction_currency_map

def get_conversion_rate_map(self):
conversion_rate_map = {}
for account in self.get("accounts"):
conversion_rate_map.setdefault(account.party or account.account, account.exchange_rate)

return conversion_rate_map

def make_gl_entries(self, cancel=0, adv_adj=0):
from erpnext.accounts.general_ledger import make_gl_entries

Expand Down
6 changes: 3 additions & 3 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ def get_gl_dict(self, args, account_currency=None, item=None):
# Update details in transaction currency
gl_dict.update(
{
"transaction_currency": self.get("currency") or self.company_currency,
"transaction_currency": args.get("currency") or self.get("currency") or self.company_currency,
"transaction_exchange_rate": self.get("conversion_rate", 1),
"debit_in_transaction_currency": self.get_value_in_transaction_currency(
account_currency, args, "debit"
Expand Down Expand Up @@ -955,10 +955,10 @@ def get_voucher_subtype(self):
return self.doctype

def get_value_in_transaction_currency(self, account_currency, args, field):
if account_currency == self.get("currency"):
if account_currency == args.get("currency") or self.get("currency"):
return args.get(field + "_in_account_currency")
else:
return flt(args.get(field, 0) / self.get("conversion_rate", 1))
return flt(args.get(field, 0) / (args.get("conversion_rate") or self.get("conversion_rate", 1)))

def validate_qty_is_not_zero(self):
if self.doctype == "Purchase Receipt":
Expand Down

0 comments on commit 3f9693b

Please sign in to comment.