refactor: DRY for disable due date logic

This commit is contained in:
tunde 2017-09-06 12:36:45 +01:00
parent 9e32387aa7
commit e7da1c5500
3 changed files with 27 additions and 40 deletions

View File

@ -373,22 +373,4 @@ frappe.ui.form.on("Purchase Invoice", {
}
})
frappe.ui.form.on("Purchase Invoice", {
payment_terms_template: function() {
cur_frm.trigger("disable_due_date");
},
disable_due_date: function() {
const disable = cur_frm.doc.payment_terms_template || (
cur_frm.doc.payment_schedule && cur_frm.doc.payment_schedule.length == 0);
cur_frm.set_df_property("due_date", "read_only", disable ? 1 : 0);
},
});
frappe.ui.form.on("Payment Schedule", {
payment_schedule_remove: function() {
cur_frm.trigger("disable_due_date");
},
});

View File

@ -565,22 +565,3 @@ var calculate_total_billing_amount = function(frm) {
refresh_field('total_billing_amount')
}
frappe.ui.form.on("Sales Invoice", {
payment_terms_template: function() {
cur_frm.trigger("disable_due_date");
},
disable_due_date: function() {
const disable = cur_frm.doc.payment_terms_template || (
cur_frm.doc.payment_schedule && cur_frm.doc.payment_schedule.length == 0);
cur_frm.set_df_property("due_date", "read_only", disable ? 1 : 0);
},
});
frappe.ui.form.on("Payment Schedule", {
payment_schedule_remove: function() {
cur_frm.trigger("disable_due_date");
},
});

View File

@ -52,7 +52,14 @@ frappe.ui.form.on(cur_frm.doctype, {
},
taxes_on_form_rendered: function(frm) {
erpnext.taxes.set_conditional_mandatory_rate_or_amount(frm.open_grid_row());
}
},
disable_due_date: function() {
const disable = cur_frm.doc.payment_terms_template || (
cur_frm.doc.payment_schedule && cur_frm.doc.payment_schedule.length != 0);
cur_frm.set_df_property("due_date", "read_only", disable ? 1 : 0);
},
});
frappe.ui.form.on('Sales Invoice Payment', {
@ -62,15 +69,32 @@ frappe.ui.form.on('Sales Invoice Payment', {
frappe.model.set_value(cdt, cdn, 'account', account)
})
}
})
});
frappe.ui.form.on("Sales Invoice", {
payment_terms_template: function() {
cur_frm.trigger("disable_due_date");
}
});
frappe.ui.form.on('Purchase Invoice', {
mode_of_payment: function(frm) {
get_payment_mode_account(frm, frm.doc.mode_of_payment, function(account){
frm.set_value('cash_bank_account', account);
})
},
payment_terms_template: function() {
cur_frm.trigger("disable_due_date");
}
})
});
frappe.ui.form.on("Payment Schedule", {
payment_schedule_remove: function() {
cur_frm.trigger("disable_due_date");
},
});
frappe.ui.form.on('Payment Entry', {
mode_of_payment: function(frm) {