From 01eae2b7588eccf12003fb42fd9787dd81b2b794 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 4 Sep 2023 20:38:10 +0530 Subject: [PATCH] refactor: gain/loss should use same posting date as payment (cherry picked from commit f7865da4d258f131529dc0fb907f7ecbcbfdb23b) --- .../doctype/payment_reconciliation/payment_reconciliation.py | 1 + erpnext/accounts/utils.py | 3 ++- erpnext/controllers/accounts_controller.py | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py index e57c3259d1f..7d294e873d4 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py @@ -634,6 +634,7 @@ def reconcile_dr_cr_note(dr_cr_notes, company): create_gain_loss_journal( company, + today(), inv.party_type, inv.party, inv.account, diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 267f22d119b..8f0ef869ad3 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -1858,6 +1858,7 @@ class QueryPaymentLedger(object): def create_gain_loss_journal( company, + posting_date, party_type, party, party_account, @@ -1876,7 +1877,7 @@ def create_gain_loss_journal( journal_entry = frappe.new_doc("Journal Entry") journal_entry.voucher_type = "Exchange Gain Or Loss" journal_entry.company = company - journal_entry.posting_date = nowdate() + journal_entry.posting_date = posting_date or nowdate() journal_entry.multi_currency = 1 journal_entry.is_system_generated = True diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index b476d0ffb48..df77e5260f5 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1042,8 +1042,10 @@ class AccountsController(TransactionBase): self.name, arg.get("referenced_row"), ): + posting_date = frappe.db.get_value(arg.voucher_type, arg.voucher_no, "posting_date") je = create_gain_loss_journal( self.company, + posting_date, arg.get("party_type"), arg.get("party"), party_account, @@ -1123,6 +1125,7 @@ class AccountsController(TransactionBase): je = create_gain_loss_journal( self.company, + self.posting_date, self.party_type, self.party, party_account,