feat: remove button on import of an order

This commit is contained in:
Mangesh-Khairnar 2019-05-11 20:04:03 +05:30
parent 644e181729
commit cd4289e10e
3 changed files with 50 additions and 35 deletions

View File

@ -16,25 +16,44 @@ frappe.ui.form.on('Payment Order', {
frm.add_custom_button(__('Payment Request'), function() {
frm.trigger("get_from_payment_request");
}, __("Get from"));
frm.add_custom_button(__('Payment Entry'), function() {
frm.trigger("get_from_payment_entry");
}, __("Get from"));
frm.trigger('remove_button');
}
// payment Entry
if (frm.doc.docstatus===1 && frm.doc.payment_order_type==='Payment Request') {
frm.add_custom_button(__('Create Payment Entries'),
function() {
frm.trigger("make_payment_records");
});
function() {
frm.trigger("make_payment_records");
});
}
},
remove_row_if_empty: function(frm) {
// remove if first row is empty
if (frm.doc.references.length > 0 && !frm.doc.references[0].reference_name) {
frm.doc.references = [];
}
},
remove_button: function(frm) {
let label = ["Payment Request", "Payment Entry"]
if (frm.doc.references.length > 0 && frm.doc.payment_order_type) {
label = label.reduce(x => {
x!= frm.doc.payment_order_type;
return x;
});
frm.remove_custom_button(label, "Get from");
}
},
get_from_payment_entry: function(frm) {
// remove if first row is empty
if (!frm.doc.references[0].reference_name) {
frm.doc.references = [];
}
frm.trigger("remove_row_if_empty");
erpnext.utils.map_current_doc({
method: "erpnext.accounts.doctype.payment_entry.payment_entry.make_payment_order",
source_doctype: "Payment Entry",
@ -52,10 +71,7 @@ frappe.ui.form.on('Payment Order', {
},
get_from_payment_request: function(frm) {
// remove if first row is empty
if (!frm.doc.references[0].reference_name) {
frm.doc.references = [];
}
frm.trigger("remove_row_if_empty")
erpnext.utils.map_current_doc({
method: "erpnext.accounts.doctype.payment_request.payment_request.make_payment_order",
source_doctype: "Payment Request",
@ -116,5 +132,4 @@ frappe.ui.form.on('Payment Order', {
dialog.show();
},
});

View File

@ -79,6 +79,7 @@
"fieldtype": "Select",
"label": "Payment Order Type",
"options": "\nPayment Request\nPayment Entry",
"read_only": 1,
"reqd": 1
},
{
@ -98,7 +99,7 @@
}
],
"is_submittable": 1,
"modified": "2019-05-08 16:00:09.027739",
"modified": "2019-05-09 13:57:12.974008",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Order",

View File

@ -1,30 +1,29 @@
frappe.ui.form.on('Payment Order', {
refresh: function(frm) {
if (frm.doc.docstatus==1 && frm.doc.payment_order_type==='Payment Entry') {
frm.add_custom_button(__('Generate Text File'),
function() {
frm.trigger("generate_text_and_download_file");
});
}
},
generate_text_and_download_file: (frm) => {
return frappe.call({
method: "erpnext.regional.india.bank_remittance_txt.generate_report",
args: {
name: frm.doc.name
},
freeze: true,
callback: function(r) {
{
frm.refresh();
const a = document.createElement('a');
let file_obj = r.message;
if (frm.doc.docstatus==1 && frm.doc.payment_order_type==='Payment Entry') {
frm.add_custom_button(__('Generate Text File'), function() {
frm.trigger("generate_text_and_download_file");
});
}
},
generate_text_and_download_file: (frm) => {
return frappe.call({
method: "erpnext.regional.india.bank_remittance_txt.generate_report",
args: {
name: frm.doc.name
},
freeze: true,
callback: function(r) {
{
frm.refresh();
const a = document.createElement('a');
let file_obj = r.message;
a.href = file_obj.file_url;
a.target = '_blank';
a.download = file_obj.file_name;
a.click();
}
}
});
}
}
});
}
});