From 9a58823867dff30491c2bf4b1fa4d921955b4b1c Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 29 Apr 2024 17:01:48 +0530 Subject: [PATCH 1/4] fix: Merge debit and credit in transaction currency while merging gle with similar head (cherry picked from commit e43697d359a9253bca7dbb62827ba0332dbd49dd) --- .../sales_invoice/test_sales_invoice.py | 43 +++++++++++++++++++ erpnext/accounts/general_ledger.py | 6 +++ 2 files changed, 49 insertions(+) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 7d7e1633044..ee8658a9414 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -1766,6 +1766,49 @@ class TestSalesInvoice(FrappeTestCase): self.assertTrue(gle) + def test_gle_in_transaction_currency(self): + # create multi currency sales invoice with 2 items with same income account + si = create_sales_invoice( + customer="_Test Customer USD", + debit_to="_Test Receivable USD - _TC", + currency="USD", + conversion_rate=50, + do_not_submit=True, + ) + # add 2nd item with same income account + si.append( + "items", + { + "item_code": "_Test Item", + "qty": 1, + "rate": 80, + "income_account": "Sales - _TC", + "cost_center": "_Test Cost Center - _TC", + }, + ) + si.submit() + + gl_entries = frappe.db.sql( + """select transaction_currency, transaction_exchange_rate, + debit_in_transaction_currency, credit_in_transaction_currency + from `tabGL Entry` + where voucher_type='Sales Invoice' and voucher_no=%s and account = 'Sales - _TC' + order by account asc""", + si.name, + as_dict=1, + ) + + expected_gle = { + "transaction_currency": "USD", + "transaction_exchange_rate": 50, + "debit_in_transaction_currency": 0, + "credit_in_transaction_currency": 180, + } + + for gle in gl_entries: + for field in expected_gle: + self.assertEqual(expected_gle[field], gle[field]) + def test_invoice_exchange_rate(self): si = create_sales_invoice( customer="_Test Customer USD", diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 74868d413b4..0ff9e973e59 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -238,10 +238,16 @@ def merge_similar_entries(gl_map, precision=None): same_head.debit_in_account_currency = flt(same_head.debit_in_account_currency) + flt( entry.debit_in_account_currency ) + same_head.debit_in_transaction_currency = flt(same_head.debit_in_transaction_currency) + flt( + entry.debit_in_transaction_currency + ) same_head.credit = flt(same_head.credit) + flt(entry.credit) same_head.credit_in_account_currency = flt(same_head.credit_in_account_currency) + flt( entry.credit_in_account_currency ) + same_head.credit_in_transaction_currency = flt(same_head.credit_in_transaction_currency) + flt( + entry.credit_in_transaction_currency + ) else: merged_gl_map.append(entry) From f7e165b5ffd029973bd4cb54d1f852d22dda96df Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 29 Apr 2024 17:24:31 +0530 Subject: [PATCH 2/4] fix: Patch to fix the incorrect debit and credit in transaction currency (cherry picked from commit e0d12ba4d02776e5de779d5b64c9713b6521ecb8) # Conflicts: # erpnext/patches.txt --- erpnext/patches.txt | 8 ++++++- ...ix_debit_credit_in_transaction_currency.py | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 erpnext/patches/v15_0/fix_debit_credit_in_transaction_currency.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index c74a2839958..4a664a41298 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -360,4 +360,10 @@ erpnext.patches.v15_0.create_accounting_dimensions_in_payment_request erpnext.patches.v14_0.migrate_gl_to_payment_ledger erpnext.stock.doctype.delivery_note.patches.drop_unused_return_against_index # 2023-12-20 erpnext.patches.v14_0.set_maintain_stock_for_bom_item -erpnext.patches.v15_0.delete_orphaned_asset_movement_item_records \ No newline at end of file +<<<<<<< HEAD +erpnext.patches.v15_0.delete_orphaned_asset_movement_item_records +======= +erpnext.patches.v15_0.delete_orphaned_asset_movement_item_records +erpnext.patches.v15_0.remove_cancelled_asset_capitalization_from_asset +erpnext.patches.v15_0.fix_debit_credit_in_transaction_currency +>>>>>>> e0d12ba4d0 (fix: Patch to fix the incorrect debit and credit in transaction currency) diff --git a/erpnext/patches/v15_0/fix_debit_credit_in_transaction_currency.py b/erpnext/patches/v15_0/fix_debit_credit_in_transaction_currency.py new file mode 100644 index 00000000000..e0cc8f85a55 --- /dev/null +++ b/erpnext/patches/v15_0/fix_debit_credit_in_transaction_currency.py @@ -0,0 +1,21 @@ +import frappe + + +def execute(): + # update debit and credit in transaction currency: + # if transaction currency is same as account currency, + # then debit and credit in transaction currency is same as debit and credit in account currency + # else debit and credit divided by exchange rate + + # nosemgrep + frappe.db.sql( + """ + UPDATE `tabGL Entry` + SET + debit_in_transaction_currency = IF(transaction_currency = account_currency, debit_in_account_currency, debit / transaction_exchange_rate), + credit_in_transaction_currency = IF(transaction_currency = account_currency, credit_in_account_currency, credit / transaction_exchange_rate) + WHERE + transaction_exchange_rate > 0 + and transaction_currency is not null + """ + ) From 81afdcf745a69c335710a0630173810bd517fc19 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 8 May 2024 17:57:43 +0530 Subject: [PATCH 3/4] fix: resolved conflict --- erpnext/patches.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 4a664a41298..91c77219510 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -360,10 +360,6 @@ erpnext.patches.v15_0.create_accounting_dimensions_in_payment_request erpnext.patches.v14_0.migrate_gl_to_payment_ledger erpnext.stock.doctype.delivery_note.patches.drop_unused_return_against_index # 2023-12-20 erpnext.patches.v14_0.set_maintain_stock_for_bom_item -<<<<<<< HEAD -erpnext.patches.v15_0.delete_orphaned_asset_movement_item_records -======= erpnext.patches.v15_0.delete_orphaned_asset_movement_item_records erpnext.patches.v15_0.remove_cancelled_asset_capitalization_from_asset erpnext.patches.v15_0.fix_debit_credit_in_transaction_currency ->>>>>>> e0d12ba4d0 (fix: Patch to fix the incorrect debit and credit in transaction currency) From 5039f45be461f0467f6c50a0b770fc35d24896ae Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 8 May 2024 18:23:30 +0530 Subject: [PATCH 4/4] fix: resolved conflict --- erpnext/patches.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 91c77219510..5b3462231d3 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -361,5 +361,4 @@ erpnext.patches.v14_0.migrate_gl_to_payment_ledger erpnext.stock.doctype.delivery_note.patches.drop_unused_return_against_index # 2023-12-20 erpnext.patches.v14_0.set_maintain_stock_for_bom_item erpnext.patches.v15_0.delete_orphaned_asset_movement_item_records -erpnext.patches.v15_0.remove_cancelled_asset_capitalization_from_asset erpnext.patches.v15_0.fix_debit_credit_in_transaction_currency