diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 37488ebd8d681a887f632c46de70878d744a154f..ffcb208e80a2dc0130c572e4fbc03b55e69f8e86 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -1733,6 +1733,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 ff8a450d2ad8af6b261791a3f2def3047fa61cf9..59d53cb297b48d33ff2614fe8932e3fc2ec7c702 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -244,14 +244,21 @@ 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 + ) if not same_head.remarks: same_head.remarks = entry.remarks else: same_head.remarks += f"\n{entry.remarks}" + else: merged_gl_map.append(entry) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index ac0be698b71312259b69c0f63d30af49fbf217b5..0e4fac603de870bfe79574d791b1edfc5c12b5c5 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -390,3 +390,5 @@ execute:frappe.delete_doc_if_exists("DocType", "Integration References") 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.remove_cancelled_asset_capitalization_from_asset +erpnext.patches.v15_0.fix_debit_credit_in_transaction_currency \ No newline at end of file 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 0000000000000000000000000000000000000000..e0cc8f85a558d459356f9b19dc7ed29ce32aa14f --- /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 + """ + )