From 6e5b9813ab95e1d0f296dfb7a5678ce38416d844 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 --- erpnext/accounts/utils.py | 3 ++- erpnext/controllers/accounts_controller.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 06d05cbbb6d3..eed74a5f0177 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -1888,6 +1888,7 @@ def get_voucher_outstandings( def create_gain_loss_journal( company, + posting_date, party_type, party, party_account, @@ -1906,7 +1907,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 fd2be2c7f7f8..9725c2572969 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1096,8 +1096,10 @@ def make_exchange_gain_loss_journal(self, args: dict = None) -> None: 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, @@ -1177,6 +1179,7 @@ def make_exchange_gain_loss_journal(self, args: dict = None) -> None: je = create_gain_loss_journal( self.company, + self.posting_date, self.party_type, self.party, party_account,