fix: show "Create Dunning" when any scheduled payment is overdue

This commit is contained in:
barredterra 2021-12-28 23:50:05 +01:00 committed by marination
parent 028d19f32d
commit fd6d86eefc

View File

@ -138,8 +138,14 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends e
cur_frm.events.create_invoice_discounting(cur_frm);
}, __('Create'));
if (doc.due_date < frappe.datetime.get_today()) {
cur_frm.add_custom_button(__('Dunning'), function() {
const payment_is_overdue = doc.payment_schedule.map(
row => Date.parse(row.due_date) < Date.now()
).reduce(
(prev, current) => prev || current
);
if (payment_is_overdue) {
cur_frm.add_custom_button(__('Dunning'), function () {
cur_frm.events.create_dunning(cur_frm);
}, __('Create'));
}