<commit_before>// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt

frappe.provide("erpnext.projects");

cur_frm.add_fetch("project", "company", "company");

frappe.ui.form.on("Task", {
	onload: function(frm) {
		frm.set_query("task", "depends_on", function() {
			var filters = {
				name: ["!=", frm.doc.name]
			};
			if(frm.doc.project) filters["project"] = frm.doc.project;
			return {
				filters: filters
			};
		})
	},

	refresh: function(frm) {
		frm.fields_dict['parent_task'].get_query = function() {
			return {
				filters: {
					"is_group": 1,
				}
			}
		}
		if(!frm.is_group){
			var doc = frm.doc;
			if(doc.__islocal) {
				if(!frm.doc.exp_end_date) {
					frm.set_value("exp_end_date", frappe.datetime.add_days(new Date(), 7));
				}
			}

			if(!doc.__islocal) {
				if(frm.perm[0].write) {
					if(frm.doc.status!=="Completed" && frm.doc.status!=="Cancelled") {
						frm.add_custom_button(__("Completed"), function() {
							frm.set_value("status", "Completed");
							frm.save();
						});
					} else {
						frm.add_custom_button(__("Reopen"), function() {
							frm.set_value("status", "Open");
							frm.save();
						});
					}
				}
			}
		}
	},

	setup: function(frm) {
		frm.fields_dict.project.get_query = function() {
			return {
				query: "erpnext.projects.doctype.task.task.get_project"
			}
		};
	},

	is_group: function (frm) {
		frappe.call({
			method: "erpnext.projects.doctype.task.task.check_if_child_exists",
			args: {<commit_msg>fix(projects): Remove hardcode of expected end date for new Tasks (#17717)<commit_after>// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt

frappe.provide("erpnext.projects");

cur_frm.add_fetch("project", "company", "company");

frappe.ui.form.on("Task", {
	onload: function(frm) {
		frm.set_query("task", "depends_on", function() {
			var filters = {
				name: ["!=", frm.doc.name]
			};
			if(frm.doc.project) filters["project"] = frm.doc.project;
			return {
				filters: filters
			};
		})
	},

	refresh: function(frm) {
		frm.fields_dict['parent_task'].get_query = function() {
			return {
				filters: {
					"is_group": 1,
				}
			}
		}

		if(!frm.doc.is_group){
			if (!frm.is_new()) {
				if (frm.perm[0].write) {
					if (!["Closed", "Cancelled"].includes(frm.doc.status)) {
						frm.add_custom_button(__("Close"), () => {
							frm.set_value("status", "Closed");
							frm.save();
						});
					} else {
						frm.add_custom_button(__("Reopen"), () => {
							frm.set_value("status", "Open");
							frm.save();
						});
					}
				}
			}
		}
	},

	setup: function(frm) {
		frm.fields_dict.project.get_query = function() {
			return {
				query: "erpnext.projects.doctype.task.task.get_project"
			}
		};
	},

	is_group: function (frm) {
		frappe.call({
			method: "erpnext.projects.doctype.task.task.check_if_child_exists",
			args: {
{'fraction_non_alphanumeric': 0.18294314381270904, 'fraction_numerical': 0.006688963210702341, 'mean_word_length': 3.0309973045822103, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4922656', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1130, 'n_words': 172}