Merge pull request #19758 from hrwX/new_invoice_fix

fix(Project): add project in child for items
This commit is contained in:
Deepesh Garg 2019-12-08 20:23:11 +05:30 committed by GitHub
commit dda1ef6b13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,20 +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); 'Purchase Order': () => {
open_form(frm, "Purchase Order", "Purchase Order Item", "items");
// add a new row and set the project },
let time_log = frappe.model.get_new_doc('Timesheet Detail'); 'Purchase Receipt': () => {
time_log.project = frm.doc.name; open_form(frm, "Purchase Receipt", "Purchase Receipt Item", "items");
time_log.parent = new_doc.name; },
time_log.parentfield = 'time_logs'; 'Purchase Invoice': () => {
time_log.parenttype = 'Timesheet'; open_form(frm, "Purchase Invoice", "Purchase Invoice Item", "items");
new_doc.time_logs = [time_log];
frappe.ui.form.make_quick_entry(doctype, null, null, new_doc);
});
}, },
}; };
}, },
@ -80,7 +76,7 @@ frappe.ui.form.on("Project", {
frm.events.set_status(frm, 'Cancelled'); frm.events.set_status(frm, 'Cancelled');
}, __('Set Status')); }, __('Set Status'));
} }
if (frappe.model.can_read("Task")) { if (frappe.model.can_read("Task")) {
frm.add_custom_button(__("Gantt Chart"), function () { frm.add_custom_button(__("Gantt Chart"), function () {
frappe.route_options = { frappe.route_options = {
@ -123,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);
});
}