chore: commonize function

This commit is contained in:
Himanshu Warekar 2019-12-04 23:08:51 +05:30
parent 98aae4cf3d
commit 175d604f5f

View File

@ -4,68 +4,16 @@ frappe.ui.form.on("Project", {
setup(frm) {
frm.make_methods = {
'Timesheet': () => {
let doctype = 'Timesheet';
frappe.model.with_doctype(doctype, () => {
let new_doc = frappe.model.get_new_doc(doctype);
// add a new row and set the project
let time_log = frappe.model.get_new_doc('Timesheet Detail');
time_log.project = frm.doc.name;
time_log.parent = new_doc.name;
time_log.parentfield = 'time_logs';
time_log.parenttype = 'Timesheet';
new_doc.time_logs = [time_log];
frappe.ui.form.make_quick_entry(doctype, null, null, new_doc);
});
open_form(frm, "Timesheet", "Timesheet Detail", "time_logs");
},
'Purchase Order': () => {
let doctype = 'Purchase Order';
frappe.model.with_doctype(doctype, () => {
let new_doc = frappe.model.get_new_doc(doctype);
// add a new row and set the project
let purchase_order_item = frappe.model.get_new_doc('Purchase Order Item');
purchase_order_item.project = frm.doc.name;
purchase_order_item.parent = new_doc.name;
purchase_order_item.parentfield = 'items';
purchase_order_item.parenttype = 'Purchase Order';
new_doc.items = [purchase_order_item];
frappe.ui.form.make_quick_entry(doctype, null, null, new_doc);
});
open_form(frm, "Purchase Order", "Purchase Order Item", "items");
},
'Purchase Receipt': () => {
let doctype = 'Purchase Receipt';
frappe.model.with_doctype(doctype, () => {
let new_doc = frappe.model.get_new_doc(doctype);
// add a new row and set the project
let purchase_receipt_item = frappe.model.get_new_doc('Purchase Receipt Item');
purchase_receipt_item.project = frm.doc.name;
purchase_receipt_item.parent = new_doc.name;
purchase_receipt_item.parentfield = 'items';
purchase_receipt_item.parenttype = 'Purchase Receipt';
new_doc.items = [purchase_receipt_item];
frappe.ui.form.make_quick_entry(doctype, null, null, new_doc);
});
open_form(frm, "Purchase Receipt", "Purchase Receipt Item", "items");
},
'Purchase Invoice': () => {
let doctype = 'Purchase Invoice';
frappe.model.with_doctype(doctype, () => {
let new_doc = frappe.model.get_new_doc(doctype);
// add a new row and set the project
let purchase_invoice_item = frappe.model.get_new_doc('Purchase Invoice Item');
purchase_invoice_item.project = frm.doc.name;
purchase_invoice_item.parent = new_doc.name;
purchase_invoice_item.parentfield = 'items';
purchase_invoice_item.parenttype = 'Purchase Invoice';
new_doc.items = [purchase_invoice_item];
frappe.ui.form.make_quick_entry(doctype, null, null, new_doc);
});
open_form(frm, "Purchase Invoice", "Purchase Invoice Item", "items");
},
};
},
@ -171,3 +119,20 @@ frappe.ui.form.on("Project", {
},
});
function open_form(frm, doctype, child_doctype, parentfield) {
frappe.model.with_doctype(doctype, () => {
let new_doc = frappe.model.get_new_doc(doctype);
// add a new row and set the project
let new_child_doc = frappe.model.get_new_doc(child_doctype);
new_child_doc.project = frm.doc.name;
new_child_doc.parent = new_doc.name;
new_child_doc.parentfield = parentfield;
new_child_doc.parenttype = doctype;
new_doc[parentfield] = [new_child_doc];
frappe.ui.form.make_quick_entry(doctype, null, null, new_doc);
});
}