chore: commonize function
This commit is contained in:
parent
98aae4cf3d
commit
175d604f5f
@ -4,68 +4,16 @@ frappe.ui.form.on("Project", {
|
|||||||
setup(frm) {
|
setup(frm) {
|
||||||
frm.make_methods = {
|
frm.make_methods = {
|
||||||
'Timesheet': () => {
|
'Timesheet': () => {
|
||||||
let doctype = 'Timesheet';
|
open_form(frm, "Timesheet", "Timesheet Detail", "time_logs");
|
||||||
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);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
'Purchase Order': () => {
|
'Purchase Order': () => {
|
||||||
let doctype = 'Purchase Order';
|
open_form(frm, "Purchase Order", "Purchase Order Item", "items");
|
||||||
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);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
'Purchase Receipt': () => {
|
'Purchase Receipt': () => {
|
||||||
let doctype = 'Purchase Receipt';
|
open_form(frm, "Purchase Receipt", "Purchase Receipt Item", "items");
|
||||||
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);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
'Purchase Invoice': () => {
|
'Purchase Invoice': () => {
|
||||||
let doctype = 'Purchase Invoice';
|
open_form(frm, "Purchase Invoice", "Purchase Invoice Item", "items");
|
||||||
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);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -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);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user