Skip to content

Commit

Permalink
refactor: accomodate configurable gain loss posting date in controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ruthra-kumar committed Oct 22, 2023
1 parent 4e69b54 commit 436f7f3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
'difference_amount': d.difference_amount,
'difference_account': d.difference_account,
// TODO: make this configurable
'gain_loss_posting_date': d.reference_posting_date
'gain_loss_posting_date': d.gain_loss_posting_date
});
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,13 @@ def allocate_entries(self, args):
res.difference_account = default_exchange_gain_loss_account
res.exchange_rate = inv.get("exchange_rate")

if gain_loss_on_reconciliation_date := frappe.get_cached_value(
"Accounts Settings", None, "post_gain_loss_journal_on_reconciliation_date"
):
res.update({"gain_loss_posting_date": nowdate()})
else:
res.update({"gain_loss_posting_date": pay.get("posting_date")})

if pay.get("amount") == 0:
entries.append(res)
break
Expand Down Expand Up @@ -440,6 +447,7 @@ def get_payment_details(self, row, dr_or_cr):
"allocated_amount": flt(row.get("allocated_amount")),
"difference_amount": flt(row.get("difference_amount")),
"difference_account": row.get("difference_account"),
"difference_posting_date": row.get("gain_loss_posting_date"),
"cost_center": row.get("cost_center"),
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"is_advance",
"section_break_5",
"difference_amount",
"gain_loss_posting_date",
"column_break_7",
"difference_account",
"exchange_rate",
Expand Down Expand Up @@ -163,11 +164,16 @@
"fieldname": "invoice_posting_date",
"fieldtype": "Date",
"label": "Invoice Posting Date"
},
{
"fieldname": "gain_loss_posting_date",
"fieldtype": "Date",
"label": "Difference Posting Date"
}
],
"istable": 1,
"links": [],
"modified": "2023-10-20 17:16:46.617590",
"modified": "2023-10-22 20:38:25.147175",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Reconciliation Allocation",
Expand Down
4 changes: 3 additions & 1 deletion erpnext/accounts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,9 @@ def update_reference_in_payment_entry(
if not skip_ref_details_update_for_pe:
payment_entry.set_missing_ref_details()
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:
payment_entry.save(ignore_permissions=True)
Expand Down
6 changes: 4 additions & 2 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,9 @@ 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")
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(
self.company,
posting_date,
Expand Down Expand Up @@ -1261,7 +1263,7 @@ def make_exchange_gain_loss_journal(self, args: dict = None) -> None:

je = create_gain_loss_journal(
self.company,
self.posting_date,
args.get("difference_posting_date") or self.posting_date,
self.party_type,
self.party,
party_account,
Expand Down

0 comments on commit 436f7f3

Please sign in to comment.