fix: GL values in transaction currency via JV (#38914)

diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 79f1ab0..ddf6460 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -1031,6 +1031,10 @@
 
 	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"):
@@ -1060,6 +1064,12 @@
 						"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,
 				)
@@ -1109,6 +1119,20 @@
 
 		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
 
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 729bb67..13df9d5 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -922,7 +922,7 @@
 		# 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"
@@ -955,10 +955,10 @@
 		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":