refactor: pass gain loss posting date to controller

This commit is contained in:
ruthra kumar 2023-10-22 20:26:45 +05:30
parent 5323bb7bee
commit 7e600a6494
5 changed files with 12 additions and 3 deletions

View File

@ -293,6 +293,8 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
args.forEach(d => { args.forEach(d => {
frappe.model.set_value("Payment Reconciliation Allocation", d.docname, frappe.model.set_value("Payment Reconciliation Allocation", d.docname,
"difference_account", d.difference_account); "difference_account", d.difference_account);
frappe.model.set_value("Payment Reconciliation Allocation", d.docname,
"gain_loss_posting_date", d.gain_loss_posting_date);
}); });

View File

@ -328,6 +328,7 @@ class PaymentReconciliation(Document):
res.difference_amount = self.get_difference_amount(pay, inv, res["allocated_amount"]) res.difference_amount = self.get_difference_amount(pay, inv, res["allocated_amount"])
res.difference_account = default_exchange_gain_loss_account res.difference_account = default_exchange_gain_loss_account
res.exchange_rate = inv.get("exchange_rate") res.exchange_rate = inv.get("exchange_rate")
res.update({"gain_loss_posting_date": pay.get("posting_date")})
if pay.get("amount") == 0: if pay.get("amount") == 0:
entries.append(res) entries.append(res)
@ -434,6 +435,7 @@ class PaymentReconciliation(Document):
"allocated_amount": flt(row.get("allocated_amount")), "allocated_amount": flt(row.get("allocated_amount")),
"difference_amount": flt(row.get("difference_amount")), "difference_amount": flt(row.get("difference_amount")),
"difference_account": row.get("difference_account"), "difference_account": row.get("difference_account"),
"difference_posting_date": row.get("gain_loss_posting_date"),
"cost_center": row.get("cost_center"), "cost_center": row.get("cost_center"),
} }
) )

View File

@ -19,6 +19,7 @@
"is_advance", "is_advance",
"section_break_5", "section_break_5",
"difference_amount", "difference_amount",
"gain_loss_posting_date",
"column_break_7", "column_break_7",
"difference_account", "difference_account",
"exchange_rate", "exchange_rate",

View File

@ -679,7 +679,9 @@ def update_reference_in_payment_entry(
if not skip_ref_details_update_for_pe: if not skip_ref_details_update_for_pe:
payment_entry.set_missing_ref_details() payment_entry.set_missing_ref_details()
payment_entry.set_amounts() payment_entry.set_amounts()
payment_entry.make_exchange_gain_loss_journal() payment_entry.make_exchange_gain_loss_journal(
frappe._dict({"difference_posting_date": d.difference_posting_date})
)
if not do_not_save: if not do_not_save:
payment_entry.save(ignore_permissions=True) payment_entry.save(ignore_permissions=True)

View File

@ -1178,7 +1178,9 @@ class AccountsController(TransactionBase):
self.name, self.name,
arg.get("referenced_row"), arg.get("referenced_row"),
): ):
posting_date = frappe.db.get_value(arg.voucher_type, arg.voucher_no, "posting_date") posting_date = arg.get("difference_posting_date") or frappe.db.get_value(
arg.voucher_type, arg.voucher_no, "posting_date"
)
je = create_gain_loss_journal( je = create_gain_loss_journal(
self.company, self.company,
posting_date, posting_date,
@ -1261,7 +1263,7 @@ class AccountsController(TransactionBase):
je = create_gain_loss_journal( je = create_gain_loss_journal(
self.company, self.company,
self.posting_date, args.get("difference_posting_date") if args else self.posting_date,
self.party_type, self.party_type,
self.party, self.party,
party_account, party_account,