From 568b582b6a38edcd7b25773d8b1cb2d000fa4632 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 21 Feb 2025 15:40:35 +0530 Subject: [PATCH 01/20] refactor: use highest precision for storing exc rate (cherry picked from commit b115bf2e2a6a510f761f0a73124bfa915cdfca46) --- erpnext/accounts/doctype/gl_entry/gl_entry.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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", From 5761cfb3d55b3cf9e93fd13cb627c716a0882502 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 21 Feb 2025 15:42:01 +0530 Subject: [PATCH 02/20] refactor: set tr currency dr & cr directly on parent document (cherry picked from commit e9af5670334ca8fa45cf42414989abca09cdb45a) --- .../purchase_invoice/purchase_invoice.py | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 3ab214751f7..87112ea7c92 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -871,8 +871,14 @@ 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_rate(gl_entries) return gl_entries + def set_transaction_currency_rate(self, gl_entries): + for x in gl_entries: + x["transaction_currency"] = self.currency + x["transaction_exchange_rate"] = self.get("conversion_rate") or 1 + def check_asset_cwip_enabled(self): # Check if there exists any item with cwip accounting enabled in it's asset category for item in self.get("items"): @@ -916,6 +922,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, @@ -1054,7 +1061,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( { @@ -1062,8 +1071,8 @@ 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"]), "project": item.project or self.project, }, item=item, @@ -1099,7 +1108,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) @@ -1110,7 +1119,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, }, @@ -1332,6 +1342,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, @@ -1460,6 +1471,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, @@ -1481,6 +1493,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, @@ -1505,6 +1518,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, @@ -1525,6 +1539,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, From eb0df50f1bdcd1aba41ef2eae7d4dcfc4b470958 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 24 Feb 2025 21:58:59 +0530 Subject: [PATCH 03/20] refactor: handle stocked items (cherry picked from commit 7ff3977394c8f2935601a3a753778bd6dd5a5592) --- erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 87112ea7c92..b1d6ec15e3c 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -1049,6 +1049,7 @@ class PurchaseInvoice(BuyingController): "account": item.expense_account, "against": self.supplier, "debit": warehouse_debit_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 or self.project, From 133dca1824dec338e7b796d41ca4da59c7a13ec9 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Tue, 25 Feb 2025 14:10:00 +0530 Subject: [PATCH 04/20] refactor: handle stocked items (cherry picked from commit ee93ed8c970deff88ef54fdcda2c5607959d29d8) --- .../accounts/doctype/purchase_invoice/purchase_invoice.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index b1d6ec15e3c..a50f7df0c09 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -998,6 +998,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, @@ -1018,6 +1019,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, @@ -1032,6 +1034,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, @@ -1074,6 +1077,7 @@ class PurchaseInvoice(BuyingController): "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "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, @@ -1096,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, @@ -1195,6 +1200,7 @@ class PurchaseInvoice(BuyingController): "account": stock_rbnb, "against": self.supplier, "debit": flt(item.item_tax_amount, item.precision("item_tax_amount")), + "debit_in_transaction_currency": item.net_amount, "remarks": self.remarks or _("Accounting Entry for Stock"), "cost_center": self.cost_center, "project": item.project or self.project, @@ -1310,6 +1316,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, From e0b5386bf0800393f4c49c741600257f000c91f3 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 28 Feb 2025 17:26:19 +0530 Subject: [PATCH 05/20] refactor: set transaction currency dr/cr in sales invoice (cherry picked from commit 3e292ef2cbed31afed297e005e04f021944542fd) # Conflicts: # erpnext/accounts/doctype/sales_invoice/sales_invoice.py --- .../doctype/sales_invoice/sales_invoice.py | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 9fcb1ae526c..cd556d77274 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1274,6 +1274,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, @@ -1305,6 +1306,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, @@ -1322,6 +1326,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, @@ -1420,6 +1425,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, }, @@ -1471,6 +1477,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, @@ -1485,6 +1492,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, @@ -1518,6 +1526,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, @@ -1537,6 +1546,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, @@ -1573,6 +1583,7 @@ class SalesInvoice(SellingController): ) ) +<<<<<<< HEAD gl_entries.append( self.get_gl_dict( { @@ -1586,6 +1597,44 @@ class SalesInvoice(SellingController): ) else: frappe.throw(_("Select change amount account"), title=_("Mandatory Field")) +======= + if not self.account_for_change_amount: + frappe.throw(_("Please set Account for Change Amount"), title=_("Mandatory Field")) + + return [ + self.get_gl_dict( + { + "account": self.debit_to, + "party_type": "Customer", + "party": self.customer, + "against": self.account_for_change_amount, + "debit": flt(self.base_change_amount), + "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, + "against_voucher_type": self.doctype, + "cost_center": self.cost_center, + "project": self.project, + }, + self.party_account_currency, + item=self, + ), + self.get_gl_dict( + { + "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, + ), + ] +>>>>>>> 3e292ef2cb (refactor: set transaction currency dr/cr in sales invoice) def make_write_off_gl_entry(self, gl_entries): # write off entries, applicable if only pos @@ -1610,6 +1659,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, @@ -1630,6 +1682,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, @@ -1674,6 +1729,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") ), From d7baa451e339c89f391448b679ba10f4d2edc318 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 28 Feb 2025 17:30:25 +0530 Subject: [PATCH 06/20] refactor: move utility method to controller (cherry picked from commit d1d06885dc647d0ca964850019d32d3091d1de46) --- .../accounts/doctype/purchase_invoice/purchase_invoice.py | 7 +------ erpnext/accounts/doctype/sales_invoice/sales_invoice.py | 1 + erpnext/controllers/accounts_controller.py | 5 +++++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index a50f7df0c09..5d12066757e 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -871,14 +871,9 @@ 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_rate(gl_entries) + self.set_transaction_currency_and_rate_in_gl_map(gl_entries) return gl_entries - def set_transaction_currency_rate(self, gl_entries): - for x in gl_entries: - x["transaction_currency"] = self.currency - x["transaction_exchange_rate"] = self.get("conversion_rate") or 1 - def check_asset_cwip_enabled(self): # Check if there exists any item with cwip accounting enabled in it's asset category for item in self.get("items"): diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index cd556d77274..6f1b3a69605 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1241,6 +1241,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): diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index d67322eae8d..bc02484a37a 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -2758,6 +2758,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): From 00cbc89b5f9e44b9419c6ec929e206d3d4d5a845 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 3 Mar 2025 12:22:35 +0530 Subject: [PATCH 07/20] refactor: handle Journal entries (cherry picked from commit 9f3847c0f8b985eb21d29bb4687c1762f467e2ba) --- .../doctype/journal_entry/journal_entry.py | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 4eb74cb2b6f..c82b224d83c 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -1060,14 +1060,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 foregin 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"): @@ -1092,6 +1093,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, From 66dc79ceb52b02de075d1e705d20253b8cc387e8 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Tue, 4 Mar 2025 14:19:38 +0530 Subject: [PATCH 08/20] refactor: handle payment entry (cherry picked from commit 5c86e3ce859d9f8baa93bc709fd75abab7849700) --- .../doctype/payment_entry/payment_entry.py | 42 +++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 45462398e1c..588be1df4bf 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1222,10 +1222,15 @@ class PaymentEntry(AccountsController): self.setup_party_account_field() 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.currency = self.paid_from_account_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.currency = self.paid_to_account_currency + self.transaction_currency = self.paid_to_account_currency + self.transaction_exchange_rate = self.target_exchange_rate gl_entries = [] self.add_party_gl_entries(gl_entries) @@ -1304,6 +1309,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, ) @@ -1348,6 +1356,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, @@ -1444,9 +1455,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, @@ -1464,8 +1482,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", @@ -1487,6 +1510,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, @@ -1502,6 +1528,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, }, @@ -1537,6 +1566,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, }, @@ -1562,6 +1593,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, }, @@ -1584,6 +1617,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, }, From 1d56931050d86c041a1353c64ff40251d6ff0bf9 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 6 Mar 2025 11:35:18 +0530 Subject: [PATCH 09/20] refactor: set transaction currency and rate before gl map (cherry picked from commit ceca5b4c72e60bf923bf8c85c7d7be0a15e6f9fc) --- .../accounts/doctype/payment_entry/payment_entry.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 588be1df4bf..5c9f855ea5b 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1217,10 +1217,7 @@ class PaymentEntry(AccountsController): self.set("remarks", "\n".join(remarks)) - def build_gl_map(self): - if self.payment_type in ("Receive", "Pay") and not self.get("party_account_field"): - self.setup_party_account_field() - + 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 @@ -1232,6 +1229,11 @@ class PaymentEntry(AccountsController): 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() + self.set_transaction_currency_and_rate() + gl_entries = [] self.add_party_gl_entries(gl_entries) self.add_bank_gl_entries(gl_entries) @@ -1376,6 +1378,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) From b76c96820ec5ca31405e77a8d3cdc15d050bbf95 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 6 Mar 2025 14:38:18 +0530 Subject: [PATCH 10/20] fix(test): incorrect transaction exchange rate in test case (cherry picked from commit a31770d12282771969feba8c54f2e79a2290e590) --- erpnext/accounts/doctype/journal_entry/test_journal_entry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py index e95a8eaef29..4d2d14abea4 100644 --- a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py @@ -575,7 +575,7 @@ class TestJournalEntry(unittest.TestCase): 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) From 5c013172f9c558a9853173dd0f7505defc7f14f9 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 6 Mar 2025 14:54:20 +0530 Subject: [PATCH 11/20] refactor(test): save first to let the tax table populate (cherry picked from commit 23d465805b8812e7f76ef5031f08fe9a49243b36) --- .../tax_withholding_category/test_tax_withholding_category.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6ab6bcc08a2..ae0a098137a 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 @@ -519,7 +519,7 @@ class TestTaxWithholdingCategory(FrappeTestCase): 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): From 07f938cc10e54380fc0b52afb895fe3d6cdfa409 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 6 Mar 2025 15:54:14 +0530 Subject: [PATCH 12/20] refactor: isolate to specific doctypes (cherry picked from commit b348aa3b3716838b1f00f5a8266c8d9b6904a660) --- erpnext/controllers/accounts_controller.py | 27 +++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index bc02484a37a..df7452c0a01 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1119,20 +1119,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")}) From 38a3a43ba50d8c325a93188ad85a1fe15c22a6e3 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 7 Mar 2025 11:40:14 +0530 Subject: [PATCH 13/20] chore: typo (cherry picked from commit bc792c61e9dc07c9ebef4534e9e1e7904adb592f) --- erpnext/accounts/doctype/journal_entry/journal_entry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index c82b224d83c..9e1eaf25442 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -1065,7 +1065,7 @@ class JournalEntry(AccountsController): if self.multi_currency: for row in self.get("accounts"): if row.account_currency != company_currency: - # Journal assumes the first foregin currency as transaction currency + # Journal assumes the first foreign currency as transaction currency self.transaction_currency = row.account_currency self.transaction_exchange_rate = row.exchange_rate break From 002685fc892eca2a2a3fd49c7bf277dd9b7f84b0 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 7 Mar 2025 13:22:08 +0530 Subject: [PATCH 14/20] fix: incorrect category in list (cherry picked from commit 6545467aecac894701b2e62719083d3db195a241) --- erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 5d12066757e..c514f379406 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -953,7 +953,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) ] From 2c73e31742bf6f2477996759355c4764a54fb71e Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 7 Mar 2025 13:22:20 +0530 Subject: [PATCH 15/20] refactor: convert tax amount using exchange rate (cherry picked from commit 7528ef147a0375dc863f2d4d0720f02dbcd71631) --- erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index c514f379406..9d19109217d 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -1195,7 +1195,8 @@ class PurchaseInvoice(BuyingController): "account": stock_rbnb, "against": self.supplier, "debit": flt(item.item_tax_amount, item.precision("item_tax_amount")), - "debit_in_transaction_currency": item.net_amount, + "debit_in_transaction_currency": item.item_tax_amount + / self.conversion_rate, "remarks": self.remarks or _("Accounting Entry for Stock"), "cost_center": self.cost_center, "project": item.project or self.project, From 57e0f73595e7716f57d644b4a180b76695d91492 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 7 Mar 2025 14:43:48 +0530 Subject: [PATCH 16/20] refactor: trx currency dr and cr for tax rows and item rows (cherry picked from commit 4cd3f3531c965c318c635ebe2600240c9f9782fd) --- .../purchase_invoice/purchase_invoice.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 9d19109217d..146b2f5b210 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -1047,7 +1047,10 @@ class PurchaseInvoice(BuyingController): "account": item.expense_account, "against": self.supplier, "debit": warehouse_debit_amount, - "debit_in_transaction_currency": item.net_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, @@ -1195,8 +1198,10 @@ class PurchaseInvoice(BuyingController): "account": stock_rbnb, "against": self.supplier, "debit": flt(item.item_tax_amount, item.precision("item_tax_amount")), - "debit_in_transaction_currency": item.item_tax_amount - / self.conversion_rate, + "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, @@ -1393,6 +1398,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, @@ -1411,6 +1420,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, From cd21e5c6522d8e5cfa736cc6e560fd3e37faafa4 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 7 Mar 2025 17:00:21 +0530 Subject: [PATCH 17/20] refactor: handle rounding diff for trx currency dr and cr (cherry picked from commit 455a55b2ce5dddfc534efae8efb4b58fb50b949e) --- erpnext/accounts/general_ledger.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 7d0bf2cca11..cb267972c70 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -430,7 +430,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 ( @@ -441,9 +441,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" @@ -455,14 +455,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): @@ -489,7 +498,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 ) @@ -534,6 +543,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, From f303245fae9169ee2d629c5e811a53fb9d60433f Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 7 Mar 2025 17:39:21 +0530 Subject: [PATCH 18/20] test: assert total debit and credit for trx currency (cherry picked from commit 55d06361232baa64551c90db25d5231f7dd32320) --- .../purchase_invoice/test_purchase_invoice.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index e2386122522..192f9cc81d2 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -2639,6 +2639,36 @@ class TestPurchaseInvoice(FrappeTestCase, 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( From 8f4c1e7169b0e4ba76de7def6f8fd12d5405333d Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Sat, 8 Mar 2025 11:45:12 +0530 Subject: [PATCH 19/20] refactor: internal transfer gl (cherry picked from commit f1d8feec15595e9529af91827d106e77c1c0354d) --- erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 146b2f5b210..5092c365fef 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -1439,6 +1439,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, }, From 0b8673777aa3f7119b2c34a169d01683c5a330d4 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Sat, 8 Mar 2025 12:11:54 +0530 Subject: [PATCH 20/20] chore: resolve conflict --- .../doctype/sales_invoice/sales_invoice.py | 41 +------------------ 1 file changed, 2 insertions(+), 39 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 6f1b3a69605..92902c78e8e 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1572,6 +1572,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, @@ -1584,13 +1585,13 @@ class SalesInvoice(SellingController): ) ) -<<<<<<< HEAD gl_entries.append( self.get_gl_dict( { "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, @@ -1598,44 +1599,6 @@ class SalesInvoice(SellingController): ) else: frappe.throw(_("Select change amount account"), title=_("Mandatory Field")) -======= - if not self.account_for_change_amount: - frappe.throw(_("Please set Account for Change Amount"), title=_("Mandatory Field")) - - return [ - self.get_gl_dict( - { - "account": self.debit_to, - "party_type": "Customer", - "party": self.customer, - "against": self.account_for_change_amount, - "debit": flt(self.base_change_amount), - "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, - "against_voucher_type": self.doctype, - "cost_center": self.cost_center, - "project": self.project, - }, - self.party_account_currency, - item=self, - ), - self.get_gl_dict( - { - "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, - ), - ] ->>>>>>> 3e292ef2cb (refactor: set transaction currency dr/cr in sales invoice) def make_write_off_gl_entry(self, gl_entries): # write off entries, applicable if only pos