fix: pull project from task (#18776)

This commit is contained in:
Rohan 2019-09-05 14:53:43 +05:30 committed by Nabin Hait
parent 9d77e9f719
commit 77da3b4347
2 changed files with 14 additions and 3 deletions

View File

@ -147,6 +147,15 @@ frappe.ui.form.on("Timesheet Detail", {
calculate_time_and_amount(frm);
},
task: (frm, cdt, cdn) => {
let row = frm.selected_doc;
if (row.task) {
frappe.db.get_value("Task", row.task, "project", (r) => {
frappe.model.set_value(cdt, cdn, "project", r.project);
});
}
},
from_time: function(frm, cdt, cdn) {
calculate_end_time(frm, cdt, cdn);
},
@ -200,9 +209,6 @@ frappe.ui.form.on("Timesheet Detail", {
},
activity_type: function(frm, cdt, cdn) {
frm.script_manager.copy_from_first_row('time_logs', frm.selected_doc,
'project');
frappe.call({
method: "erpnext.projects.doctype.timesheet.timesheet.get_activity_cost",
args: {

View File

@ -145,12 +145,17 @@ class Timesheet(Document):
def validate_time_logs(self):
for data in self.get('time_logs'):
self.validate_overlap(data)
self.validate_task_project()
def validate_overlap(self, data):
settings = frappe.get_single('Projects Settings')
self.validate_overlap_for("user", data, self.user, settings.ignore_user_time_overlap)
self.validate_overlap_for("employee", data, self.employee, settings.ignore_employee_time_overlap)
def validate_task_project(self):
for log in self.time_logs:
log.project = log.project or frappe.db.get_value("Task", log.task, "project")
def validate_overlap_for(self, fieldname, args, value, ignore_validation=False):
if not value or ignore_validation:
return