diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.json b/erpnext/accounts/doctype/gl_entry/gl_entry.json index c285a33f73e..b438dbbe4ec 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.json +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.json @@ -279,7 +279,8 @@ { "fieldname": "transaction_exchange_rate", "fieldtype": "Float", - "label": "Transaction Exchange Rate" + "label": "Transaction Exchange Rate", + "precision": "9" }, { "fieldname": "debit_in_transaction_currency", @@ -357,7 +358,7 @@ "idx": 1, "in_create": 1, "links": [], - "modified": "2024-08-22 13:03:39.997475", + "modified": "2025-02-21 14:36:49.431166", "modified_by": "Administrator", "module": "Accounts", "name": "GL Entry", diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 4c59a58525d..47ee2a8fdeb 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -1063,14 +1063,15 @@ class JournalEntry(AccountsController): gl_map = [] company_currency = erpnext.get_company_currency(self.company) + self.transaction_currency = company_currency + self.transaction_exchange_rate = 1 if self.multi_currency: for row in self.get("accounts"): if row.account_currency != company_currency: - self.currency = row.account_currency - self.conversion_rate = row.exchange_rate + # Journal assumes the first foreign currency as transaction currency + self.transaction_currency = row.account_currency + self.transaction_exchange_rate = row.exchange_rate break - else: - self.currency = company_currency for d in self.get("accounts"): if d.debit or d.credit or (self.voucher_type == "Exchange Gain Or Loss"): @@ -1095,6 +1096,18 @@ class JournalEntry(AccountsController): "credit_in_account_currency": flt( d.credit_in_account_currency, d.precision("credit_in_account_currency") ), + "transaction_currency": self.transaction_currency, + "transaction_exchange_rate": self.transaction_exchange_rate, + "debit_in_transaction_currency": flt( + d.debit_in_account_currency, d.precision("debit_in_account_currency") + ) + if self.transaction_currency == d.account_currency + else flt(d.debit, d.precision("debit")) / self.transaction_exchange_rate, + "credit_in_transaction_currency": flt( + d.credit_in_account_currency, d.precision("credit_in_account_currency") + ) + if self.transaction_currency == d.account_currency + else flt(d.credit, d.precision("credit")) / self.transaction_exchange_rate, "against_voucher_type": d.reference_type, "against_voucher": d.reference_name, "remarks": remarks, diff --git a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py index f81655ca5fd..51718436a5a 100644 --- a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py @@ -583,7 +583,7 @@ class TestJournalEntry(IntegrationTestCase): order_by="account", ) expected = [ - {"account": "_Test Bank - _TC", "transaction_exchange_rate": 1.0}, + {"account": "_Test Bank - _TC", "transaction_exchange_rate": 85.0}, {"account": "_Test Receivable USD - _TC", "transaction_exchange_rate": 85.0}, ] self.assertEqual(expected, actual) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 46d520e7e34..b4e53b03218 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1311,15 +1311,22 @@ class PaymentEntry(AccountsController): self.set("remarks", "\n".join(remarks)) + def set_transaction_currency_and_rate(self): + company_currency = erpnext.get_company_currency(self.company) + self.transaction_currency = company_currency + self.transaction_exchange_rate = 1 + + if self.paid_from_account_currency != company_currency: + self.transaction_currency = self.paid_from_account_currency + self.transaction_exchange_rate = self.source_exchange_rate + elif self.paid_to_account_currency != company_currency: + self.transaction_currency = self.paid_to_account_currency + self.transaction_exchange_rate = self.target_exchange_rate + def build_gl_map(self): if self.payment_type in ("Receive", "Pay") and not self.get("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 + self.set_transaction_currency_and_rate() gl_entries = [] self.add_party_gl_entries(gl_entries) @@ -1400,6 +1407,9 @@ class PaymentEntry(AccountsController): "cost_center": cost_center, dr_or_cr + "_in_account_currency": d.allocated_amount, dr_or_cr: allocated_amount_in_company_currency, + dr_or_cr + "_in_transaction_currency": d.allocated_amount + if self.transaction_currency == self.party_account_currency + else allocated_amount_in_company_currency / self.transaction_exchange_rate, }, item=self, ) @@ -1444,6 +1454,9 @@ class PaymentEntry(AccountsController): "account_currency": self.party_account_currency, "cost_center": self.cost_center, dr_or_cr + "_in_account_currency": self.unallocated_amount, + dr_or_cr + "_in_transaction_currency": self.unallocated_amount + if self.party_account_currency == self.transaction_currency + else base_unallocated_amount / self.transaction_exchange_rate, dr_or_cr: base_unallocated_amount, }, item=self, @@ -1461,6 +1474,7 @@ class PaymentEntry(AccountsController): def make_advance_gl_entries( self, entry: object | dict = None, cancel: bool = 0, update_outstanding: str = "Yes" ): + self.set_transaction_currency_and_rate() gl_entries = [] self.add_advance_gl_entries(gl_entries, entry) @@ -1540,9 +1554,16 @@ class PaymentEntry(AccountsController): frappe.db.set_value("Payment Entry Reference", invoice.name, "reconcile_effect_on", posting_date) dr_or_cr, account = self.get_dr_and_account_for_advances(invoice) + base_allocated_amount = self.calculate_base_allocated_amount_for_reference(invoice) args_dict["account"] = account - args_dict[dr_or_cr] = self.calculate_base_allocated_amount_for_reference(invoice) + args_dict[dr_or_cr] = base_allocated_amount args_dict[dr_or_cr + "_in_account_currency"] = invoice.allocated_amount + args_dict[dr_or_cr + "_in_transaction_currency"] = ( + invoice.allocated_amount + if self.party_account_currency == self.transaction_currency + else base_allocated_amount / self.transaction_exchange_rate + ) + args_dict.update( { "against_voucher_type": invoice.reference_doctype, @@ -1560,8 +1581,13 @@ class PaymentEntry(AccountsController): args_dict[dr_or_cr + "_in_account_currency"] = 0 dr_or_cr = "debit" if dr_or_cr == "credit" else "credit" args_dict["account"] = self.party_account - args_dict[dr_or_cr] = self.calculate_base_allocated_amount_for_reference(invoice) + args_dict[dr_or_cr] = base_allocated_amount args_dict[dr_or_cr + "_in_account_currency"] = invoice.allocated_amount + args_dict[dr_or_cr + "_in_transaction_currency"] = ( + invoice.allocated_amount + if self.party_account_currency == self.transaction_currency + else base_allocated_amount / self.transaction_exchange_rate + ) args_dict.update( { "against_voucher_type": "Payment Entry", @@ -1583,6 +1609,9 @@ class PaymentEntry(AccountsController): "account_currency": self.paid_from_account_currency, "against": self.party if self.payment_type == "Pay" else self.paid_to, "credit_in_account_currency": self.paid_amount, + "credit_in_transaction_currency": self.paid_amount + if self.paid_from_account_currency == self.transaction_currency + else self.base_paid_amount / self.transaction_exchange_rate, "credit": self.base_paid_amount, "cost_center": self.cost_center, "post_net_value": True, @@ -1598,6 +1627,9 @@ class PaymentEntry(AccountsController): "account_currency": self.paid_to_account_currency, "against": self.party if self.payment_type == "Receive" else self.paid_from, "debit_in_account_currency": self.received_amount, + "debit_in_transaction_currency": self.received_amount + if self.paid_to_account_currency == self.transaction_currency + else self.base_received_amount / self.transaction_exchange_rate, "debit": self.base_received_amount, "cost_center": self.cost_center, }, @@ -1633,6 +1665,8 @@ class PaymentEntry(AccountsController): dr_or_cr + "_in_account_currency": base_tax_amount if account_currency == self.company_currency else d.tax_amount, + dr_or_cr + "_in_transaction_currency": base_tax_amount + / self.transaction_exchange_rate, "cost_center": d.cost_center, "post_net_value": True, }, @@ -1658,6 +1692,8 @@ class PaymentEntry(AccountsController): rev_dr_or_cr + "_in_account_currency": base_tax_amount if account_currency == self.company_currency else d.tax_amount, + rev_dr_or_cr + "_in_transaction_currency": base_tax_amount + / self.transaction_exchange_rate, "cost_center": self.cost_center, "post_net_value": True, }, @@ -1680,6 +1716,7 @@ class PaymentEntry(AccountsController): "account_currency": account_currency, "against": self.party or self.paid_from, "debit_in_account_currency": d.amount, + "debit_in_transaction_currency": d.amount / self.transaction_exchange_rate, "debit": d.amount, "cost_center": d.cost_center, }, diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index d996e319a06..92069a7ec8a 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -873,6 +873,7 @@ class PurchaseInvoice(BuyingController): self.make_payment_gl_entries(gl_entries) self.make_write_off_gl_entry(gl_entries) self.make_gle_for_rounding_adjustment(gl_entries) + self.set_transaction_currency_and_rate_in_gl_map(gl_entries) return gl_entries def check_asset_cwip_enabled(self): @@ -918,6 +919,7 @@ class PurchaseInvoice(BuyingController): "credit_in_account_currency": base_grand_total if self.party_account_currency == self.company_currency else grand_total, + "credit_in_transaction_currency": grand_total, "against_voucher": against_voucher, "against_voucher_type": self.doctype, "project": self.project, @@ -953,7 +955,7 @@ class PurchaseInvoice(BuyingController): valuation_tax_accounts = [ d.account_head for d in self.get("taxes") - if d.category in ("Valuation", "Total and Valuation") + if d.category in ("Valuation", "Valuation and Total") and flt(d.base_tax_amount_after_discount_amount) ] @@ -993,6 +995,7 @@ class PurchaseInvoice(BuyingController): "project": item.project or self.project, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "debit": warehouse_debit_amount, + "debit_in_transaction_currency": item.net_amount, }, warehouse_account[item.warehouse]["account_currency"], item=item, @@ -1013,6 +1016,7 @@ class PurchaseInvoice(BuyingController): "project": item.project or self.project, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "debit": -1 * flt(credit_amount, item.precision("base_net_amount")), + "debit_in_transaction_currency": item.net_amount, }, warehouse_account[item.from_warehouse]["account_currency"], item=item, @@ -1027,6 +1031,7 @@ class PurchaseInvoice(BuyingController): "account": item.expense_account, "against": self.supplier, "debit": flt(item.base_net_amount, item.precision("base_net_amount")), + "debit_in_transaction_currency": item.net_amount, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "cost_center": item.cost_center, "project": item.project, @@ -1044,6 +1049,10 @@ class PurchaseInvoice(BuyingController): "account": item.expense_account, "against": self.supplier, "debit": warehouse_debit_amount, + "debit_in_transaction_currency": flt( + warehouse_debit_amount / self.conversion_rate, + item.precision("net_amount"), + ), "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "cost_center": item.cost_center, "project": item.project or self.project, @@ -1056,7 +1065,9 @@ class PurchaseInvoice(BuyingController): # Amount added through landed-cost-voucher if landed_cost_entries: if (item.item_code, item.name) in landed_cost_entries: - for account, amount in landed_cost_entries[(item.item_code, item.name)].items(): + for account, base_amount in landed_cost_entries[ + (item.item_code, item.name) + ].items(): gl_entries.append( self.get_gl_dict( { @@ -1064,8 +1075,9 @@ class PurchaseInvoice(BuyingController): "against": item.expense_account, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), - "credit": flt(amount["base_amount"]), - "credit_in_account_currency": flt(amount["amount"]), + "credit": flt(base_amount["base_amount"]), + "credit_in_account_currency": flt(base_amount["amount"]), + "credit_in_transaction_currency": item.net_amount, "project": item.project or self.project, }, item=item, @@ -1088,6 +1100,7 @@ class PurchaseInvoice(BuyingController): "project": item.project or self.project, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "credit": flt(item.rm_supp_cost), + "credit_in_transaction_currency": item.net_amount, }, warehouse_account[self.supplier_warehouse]["account_currency"], item=item, @@ -1101,7 +1114,7 @@ class PurchaseInvoice(BuyingController): else item.deferred_expense_account ) - dummy, amount = self.get_amount_and_base_amount(item, None) + amount, base_amount = self.get_amount_and_base_amount(item, None) if provisional_accounting_for_non_stock_items: self.make_provisional_gl_entry(gl_entries, item) @@ -1112,7 +1125,8 @@ class PurchaseInvoice(BuyingController): { "account": expense_account, "against": self.supplier, - "debit": amount, + "debit": base_amount, + "debit_in_transaction_currency": amount, "cost_center": item.cost_center, "project": item.project or self.project, }, @@ -1186,6 +1200,10 @@ class PurchaseInvoice(BuyingController): "account": self.stock_received_but_not_billed, "against": self.supplier, "debit": flt(item.item_tax_amount, item.precision("item_tax_amount")), + "debit_in_transaction_currency": flt( + item.item_tax_amount / self.conversion_rate, + item.precision("item_tax_amount"), + ), "remarks": self.remarks or _("Accounting Entry for Stock"), "cost_center": self.cost_center, "project": item.project or self.project, @@ -1305,6 +1323,7 @@ class PurchaseInvoice(BuyingController): "account": cost_of_goods_sold_account, "against": item.expense_account, "debit": stock_adjustment_amt, + "debit_in_transaction_currency": item.net_amount, "remarks": self.get("remarks") or _("Stock Adjustment"), "cost_center": item.cost_center, "project": item.project or self.project, @@ -1338,6 +1357,7 @@ class PurchaseInvoice(BuyingController): dr_or_cr + "_in_account_currency": base_amount if account_currency == self.company_currency else amount, + dr_or_cr + "_in_transaction_currency": amount, "cost_center": tax.cost_center, }, account_currency, @@ -1384,6 +1404,10 @@ class PurchaseInvoice(BuyingController): "cost_center": tax.cost_center, "against": self.supplier, "credit": applicable_amount, + "credit_in_transaction_currency": flt( + applicable_amount / self.conversion_rate, + frappe.get_precision("Purchase Invoice Item", "item_tax_amount"), + ), "remarks": self.remarks or _("Accounting Entry for Stock"), }, item=tax, @@ -1402,6 +1426,10 @@ class PurchaseInvoice(BuyingController): "cost_center": tax.cost_center, "against": self.supplier, "credit": valuation_tax[tax.name], + "credit_in_transaction_currency": flt( + valuation_tax[tax.name] / self.conversion_rate, + frappe.get_precision("Purchase Invoice Item", "item_tax_amount"), + ), "remarks": self.remarks or _("Accounting Entry for Stock"), }, item=tax, @@ -1417,6 +1445,7 @@ class PurchaseInvoice(BuyingController): "account": self.unrealized_profit_loss_account, "against": self.supplier, "credit": flt(self.total_taxes_and_charges), + "credit_in_transaction_currency": flt(self.total_taxes_and_charges), "credit_in_account_currency": flt(self.base_total_taxes_and_charges), "cost_center": self.cost_center, }, @@ -1466,6 +1495,7 @@ class PurchaseInvoice(BuyingController): "debit_in_account_currency": self.base_paid_amount if self.party_account_currency == self.company_currency else self.paid_amount, + "debit_in_transaction_currency": self.paid_amount, "against_voucher": self.return_against if cint(self.is_return) and self.return_against else self.name, @@ -1487,6 +1517,7 @@ class PurchaseInvoice(BuyingController): "credit_in_account_currency": self.base_paid_amount if bank_account_currency == self.company_currency else self.paid_amount, + "credit_in_transaction_currency": self.paid_amount, "cost_center": self.cost_center, }, bank_account_currency, @@ -1511,6 +1542,7 @@ class PurchaseInvoice(BuyingController): "debit_in_account_currency": self.base_write_off_amount if self.party_account_currency == self.company_currency else self.write_off_amount, + "debit_in_transaction_currency": self.write_off_amount, "against_voucher": self.return_against if cint(self.is_return) and self.return_against else self.name, @@ -1531,6 +1563,7 @@ class PurchaseInvoice(BuyingController): "credit_in_account_currency": self.base_write_off_amount if write_off_account_currency == self.company_currency else self.write_off_amount, + "credit_in_transaction_currency": self.write_off_amount, "cost_center": self.cost_center or self.write_off_cost_center, }, item=self, diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index 327c69abbce..42dcda6e0ac 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -2656,6 +2656,36 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin): "Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice", original_value ) + def test_trx_currency_debit_credit_for_high_precision(self): + exc_rate = 0.737517516 + pi = make_purchase_invoice( + currency="USD", conversion_rate=exc_rate, qty=1, rate=2000, do_not_save=True + ) + pi.supplier = "_Test Supplier USD" + pi.save().submit() + + expected = ( + ("_Test Account Cost for Goods Sold - _TC", 1475.04, 0.0, 2000.0, 0.0, "USD", exc_rate), + ("_Test Payable USD - _TC", 0.0, 1475.04, 0.0, 2000.0, "USD", exc_rate), + ) + + actual = frappe.db.get_all( + "GL Entry", + filters={"voucher_no": pi.name}, + fields=[ + "account", + "debit", + "credit", + "debit_in_transaction_currency", + "credit_in_transaction_currency", + "transaction_currency", + "transaction_exchange_rate", + ], + order_by="account", + as_list=1, + ) + self.assertEqual(actual, expected) + def set_advance_flag(company, flag, default_account): frappe.db.set_value( diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index e326a165d31..dd0d52f4fa2 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1238,6 +1238,7 @@ class SalesInvoice(SellingController): self.make_write_off_gl_entry(gl_entries) self.make_gle_for_rounding_adjustment(gl_entries) + self.set_transaction_currency_and_rate_in_gl_map(gl_entries) return gl_entries def make_customer_gl_entry(self, gl_entries): @@ -1271,6 +1272,7 @@ class SalesInvoice(SellingController): "debit_in_account_currency": base_grand_total if self.party_account_currency == self.company_currency else grand_total, + "debit_in_transaction_currency": grand_total, "against_voucher": against_voucher, "against_voucher_type": self.doctype, "cost_center": self.cost_center, @@ -1302,6 +1304,9 @@ class SalesInvoice(SellingController): if account_currency == self.company_currency else flt(amount, tax.precision("tax_amount_after_discount_amount")) ), + "credit_in_transaction_currency": flt( + amount, tax.precision("tax_amount_after_discount_amount") + ), "cost_center": tax.cost_center, }, account_currency, @@ -1319,6 +1324,7 @@ class SalesInvoice(SellingController): "against": self.customer, "debit": flt(self.total_taxes_and_charges), "debit_in_account_currency": flt(self.base_total_taxes_and_charges), + "debit_in_transaction_currency": flt(self.total_taxes_and_charges), "cost_center": self.cost_center, }, account_currency, @@ -1417,6 +1423,7 @@ class SalesInvoice(SellingController): if account_currency == self.company_currency else flt(amount, item.precision("net_amount")) ), + "credit_in_transaction_currency": flt(amount, item.precision("net_amount")), "cost_center": item.cost_center, "project": item.project or self.project, }, @@ -1468,6 +1475,7 @@ class SalesInvoice(SellingController): + cstr(self.loyalty_redemption_account) + " for the Loyalty Program", "credit": self.loyalty_amount, + "credit_in_transaction_currency": self.loyalty_amount, "against_voucher": self.return_against if cint(self.is_return) else self.name, "against_voucher_type": self.doctype, "cost_center": self.cost_center, @@ -1482,6 +1490,7 @@ class SalesInvoice(SellingController): "cost_center": self.cost_center or self.loyalty_redemption_cost_center, "against": self.customer, "debit": self.loyalty_amount, + "debit_in_transaction_currency": self.loyalty_amount, "remark": "Loyalty Points redeemed by the customer", }, item=self, @@ -1515,6 +1524,7 @@ class SalesInvoice(SellingController): "credit_in_account_currency": payment_mode.base_amount if self.party_account_currency == self.company_currency else payment_mode.amount, + "credit_in_transaction_currency": payment_mode.amount, "against_voucher": against_voucher, "against_voucher_type": self.doctype, "cost_center": self.cost_center, @@ -1534,6 +1544,7 @@ class SalesInvoice(SellingController): "debit_in_account_currency": payment_mode.base_amount if payment_mode_account_currency == self.company_currency else payment_mode.amount, + "debit_in_transaction_currency": payment_mode.amount, "cost_center": self.cost_center, }, payment_mode_account_currency, @@ -1562,6 +1573,7 @@ class SalesInvoice(SellingController): "debit_in_account_currency": flt(self.base_change_amount) if self.party_account_currency == self.company_currency else flt(self.change_amount), + "debit_in_transaction_currency": flt(self.change_amount), "against_voucher": self.return_against if cint(self.is_return) and self.return_against else self.name, @@ -1577,6 +1589,7 @@ class SalesInvoice(SellingController): "account": self.account_for_change_amount, "against": self.customer, "credit": self.base_change_amount, + "credit_in_transaction_currency": self.change_amount, "cost_center": self.cost_center, }, item=self, @@ -1606,6 +1619,9 @@ class SalesInvoice(SellingController): if self.party_account_currency == self.company_currency else flt(self.write_off_amount, self.precision("write_off_amount")) ), + "credit_in_transaction_currency": flt( + self.write_off_amount, self.precision("write_off_amount") + ), "against_voucher": self.return_against if cint(self.is_return) else self.name, "against_voucher_type": self.doctype, "cost_center": self.cost_center, @@ -1626,6 +1642,9 @@ class SalesInvoice(SellingController): if write_off_account_currency == self.company_currency else flt(self.write_off_amount, self.precision("write_off_amount")) ), + "debit_in_transaction_currency": flt( + self.write_off_amount, self.precision("write_off_amount") + ), "cost_center": self.cost_center or self.write_off_cost_center or default_cost_center, }, write_off_account_currency, @@ -1670,6 +1689,9 @@ class SalesInvoice(SellingController): "credit_in_account_currency": flt( self.rounding_adjustment, self.precision("rounding_adjustment") ), + "credit_in_transaction_currency": flt( + self.rounding_adjustment, self.precision("rounding_adjustment") + ), "credit": flt( self.base_rounding_adjustment, self.precision("base_rounding_adjustment") ), diff --git a/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py b/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py index 303eeaa72d9..883d33a6dbd 100644 --- a/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py +++ b/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py @@ -529,7 +529,7 @@ class TestTaxWithholdingCategory(IntegrationTestCase): payment = get_payment_entry(order.doctype, order.name) payment.apply_tax_withholding_amount = 1 payment.tax_withholding_category = "Cumulative Threshold TDS" - payment.submit() + payment.save().submit() self.assertEqual(payment.taxes[0].tax_amount, 4000) def test_multi_category_single_supplier(self): diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 99dd81b6460..9920040c3a0 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -431,7 +431,7 @@ def process_debit_credit_difference(gl_map): voucher_no = gl_map[0].voucher_no allowance = get_debit_credit_allowance(voucher_type, precision) - debit_credit_diff = get_debit_credit_difference(gl_map, precision) + debit_credit_diff, trx_cur_debit_credit_diff = get_debit_credit_difference(gl_map, precision) if abs(debit_credit_diff) > allowance: if not ( @@ -442,9 +442,9 @@ def process_debit_credit_difference(gl_map): raise_debit_credit_not_equal_error(debit_credit_diff, voucher_type, voucher_no) elif abs(debit_credit_diff) >= (1.0 / (10**precision)): - make_round_off_gle(gl_map, debit_credit_diff, precision) + make_round_off_gle(gl_map, debit_credit_diff, trx_cur_debit_credit_diff, precision) - debit_credit_diff = get_debit_credit_difference(gl_map, precision) + debit_credit_diff, trx_cur_debit_credit_diff = get_debit_credit_difference(gl_map, precision) if abs(debit_credit_diff) > allowance: if not ( voucher_type == "Journal Entry" @@ -456,14 +456,23 @@ def process_debit_credit_difference(gl_map): def get_debit_credit_difference(gl_map, precision): debit_credit_diff = 0.0 + trx_cur_debit_credit_diff = 0 + for entry in gl_map: entry.debit = flt(entry.debit, precision) entry.credit = flt(entry.credit, precision) debit_credit_diff += entry.debit - entry.credit - debit_credit_diff = flt(debit_credit_diff, precision) + entry.debit_in_transaction_currency = flt(entry.debit_in_transaction_currency, precision) + entry.credit_in_transaction_currency = flt(entry.credit_in_transaction_currency, precision) + trx_cur_debit_credit_diff += ( + entry.debit_in_transaction_currency - entry.credit_in_transaction_currency + ) - return debit_credit_diff + debit_credit_diff = flt(debit_credit_diff, precision) + trx_cur_debit_credit_diff = flt(trx_cur_debit_credit_diff, precision) + + return debit_credit_diff, trx_cur_debit_credit_diff def get_debit_credit_allowance(voucher_type, precision): @@ -490,7 +499,7 @@ def has_opening_entries(gl_map: list) -> bool: return False -def make_round_off_gle(gl_map, debit_credit_diff, precision): +def make_round_off_gle(gl_map, debit_credit_diff, trx_cur_debit_credit_diff, precision): round_off_account, round_off_cost_center, round_off_for_opening = get_round_off_account_and_cost_center( gl_map[0].company, gl_map[0].voucher_type, gl_map[0].voucher_no ) @@ -535,6 +544,12 @@ def make_round_off_gle(gl_map, debit_credit_diff, precision): "credit_in_account_currency": debit_credit_diff if debit_credit_diff > 0 else 0, "debit": abs(debit_credit_diff) if debit_credit_diff < 0 else 0, "credit": debit_credit_diff if debit_credit_diff > 0 else 0, + "debit_in_transaction_currency": abs(trx_cur_debit_credit_diff) + if trx_cur_debit_credit_diff < 0 + else 0, + "credit_in_transaction_currency": trx_cur_debit_credit_diff + if trx_cur_debit_credit_diff > 0 + else 0, "cost_center": round_off_cost_center, "party_type": None, "party": None, diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 130475b98ee..9956d36617b 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1125,20 +1125,19 @@ class AccountsController(TransactionBase): ) # Update details in transaction currency - gl_dict.update( - { - "transaction_currency": self.get("currency") or self.company_currency, - "transaction_exchange_rate": item.get("exchange_rate", 1) - if self.doctype == "Journal Entry" and item - else self.get("conversion_rate", 1), - "debit_in_transaction_currency": self.get_value_in_transaction_currency( - account_currency, gl_dict, "debit" - ), - "credit_in_transaction_currency": self.get_value_in_transaction_currency( - account_currency, gl_dict, "credit" - ), - } - ) + if self.doctype not in ["Purchase Invoice", "Sales Invoice", "Journal Entry", "Payment Entry"]: + gl_dict.update( + { + "transaction_currency": 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, gl_dict, "debit" + ), + "credit_in_transaction_currency": self.get_value_in_transaction_currency( + account_currency, gl_dict, "credit" + ), + } + ) if not args.get("against_voucher_type") and self.get("against_voucher_type"): gl_dict.update({"against_voucher_type": self.get("against_voucher_type")}) @@ -2782,6 +2781,11 @@ class AccountsController(TransactionBase): elif self.doctype == "Payment Entry": self.make_advance_payment_ledger_for_payment() + def set_transaction_currency_and_rate_in_gl_map(self, gl_entries): + for x in gl_entries: + x["transaction_currency"] = self.currency + x["transaction_exchange_rate"] = self.get("conversion_rate") or 1 + @frappe.whitelist() def get_tax_rate(account_head):