Merge branch 'develop' of https://github.com/frappe/erpnext into project-link-for-all-accounts

This commit is contained in:
Deepesh Garg
2020-07-06 12:37:28 +05:30
179 changed files with 3346 additions and 1787 deletions

View File

@@ -68,7 +68,7 @@
"type": "Report"
},
{
"label": "Project Dashboard",
"label": "Dashboard",
"link_to": "Project",
"type": "Dashboard"
}

View File

@@ -140,52 +140,6 @@ class TestTimesheet(unittest.TestCase):
settings.ignore_employee_time_overlap = initial_setting
settings.save()
def test_timesheet_std_working_hours(self):
emp = make_employee("test_employee_6@salary.com")
company = frappe.get_doc('Company', "_Test Company")
company.standard_working_hours = 8
company.save()
timesheet = frappe.new_doc("Timesheet")
timesheet.employee = emp
timesheet.company = '_Test Company'
timesheet.append(
'time_logs',
{
"activity_type": "_Test Activity Type",
"from_time": now_datetime(),
"to_time": now_datetime() + datetime.timedelta(days= 4)
}
)
timesheet.save()
ts = frappe.get_doc('Timesheet', timesheet.name)
self.assertEqual(ts.total_hours, 32)
ts.submit()
ts.cancel()
company = frappe.get_doc('Company', "_Test Company")
company.standard_working_hours = 0
company.save()
timesheet = frappe.new_doc("Timesheet")
timesheet.employee = emp
timesheet.company = '_Test Company'
timesheet.append(
'time_logs',
{
"activity_type": "_Test Activity Type",
"from_time": now_datetime(),
"to_time": now_datetime() + datetime.timedelta(days= 4)
}
)
timesheet.save()
ts = frappe.get_doc('Timesheet', timesheet.name)
self.assertEqual(ts.total_hours, 96)
ts.submit()
ts.cancel()
def make_salary_structure_for_timesheet(employee):
salary_structure_name = "Timesheet Salary Structure Test"

View File

@@ -162,19 +162,11 @@ frappe.ui.form.on("Timesheet Detail", {
to_time: function(frm, cdt, cdn) {
var child = locals[cdt][cdn];
var time_diff = (moment(child.to_time).diff(moment(child.from_time),"seconds")) / ( 60 * 60 * 24);
var std_working_hours = 0;
if(frm._setting_hours) return;
var hours = moment(child.to_time).diff(moment(child.from_time), "seconds") / 3600;
std_working_hours = time_diff * frappe.working_hours;
if (std_working_hours < hours && std_working_hours > 0) {
frappe.model.set_value(cdt, cdn, "hours", std_working_hours);
} else {
frappe.model.set_value(cdt, cdn, "hours", hours);
}
frappe.model.set_value(cdt, cdn, "hours", hours);
},
time_logs_add: function(frm) {
@@ -236,23 +228,12 @@ var calculate_end_time = function(frm, cdt, cdn) {
let d = moment(child.from_time);
if(child.hours) {
var time_diff = (moment(child.to_time).diff(moment(child.from_time),"seconds")) / (60 * 60 * 24);
var std_working_hours = 0;
var hours = moment(child.to_time).diff(moment(child.from_time), "seconds") / 3600;
std_working_hours = time_diff * frappe.working_hours;
if (std_working_hours < hours && std_working_hours > 0) {
frappe.model.set_value(cdt, cdn, "hours", std_working_hours);
frappe.model.set_value(cdt, cdn, "to_time", d.add(hours, "hours").format(frappe.defaultDatetimeFormat));
} else {
d.add(child.hours, "hours");
frm._setting_hours = true;
frappe.model.set_value(cdt, cdn, "to_time",
d.format(frappe.defaultDatetimeFormat)).then(() => {
frm._setting_hours = false;
});
}
d.add(child.hours, "hours");
frm._setting_hours = true;
frappe.model.set_value(cdt, cdn, "to_time",
d.format(frappe.defaultDatetimeFormat)).then(() => {
frm._setting_hours = false;
});
}
};

View File

@@ -24,7 +24,6 @@ class Timesheet(Document):
self.set_status()
self.validate_dates()
self.validate_time_logs()
self.calculate_std_hours()
self.update_cost()
self.calculate_total_amounts()
self.calculate_percentage_billed()
@@ -91,17 +90,6 @@ class Timesheet(Document):
self.start_date = getdate(start_date)
self.end_date = getdate(end_date)
def calculate_std_hours(self):
std_working_hours = frappe.get_value("Company", self.company, 'standard_working_hours')
for time in self.time_logs:
if time.from_time and time.to_time:
if flt(std_working_hours) and date_diff(time.to_time, time.from_time):
time.hours = flt(std_working_hours) * date_diff(time.to_time, time.from_time)
else:
if not time.hours:
time.hours = time_diff_in_hours(time.to_time, time.from_time)
def before_cancel(self):
self.set_status()