style: format code with black

This commit is contained in:
Ankush Menat
2022-03-28 18:52:46 +05:30
parent 21e00da3d6
commit 494bd9ef78
1395 changed files with 91704 additions and 62532 deletions

View File

@@ -2,7 +2,6 @@
# For license information, please see license.txt
import frappe
from frappe import _
from frappe.utils import flt, time_diff_in_hours
@@ -15,52 +14,45 @@ def get_columns():
"fieldtype": "Link",
"fieldname": "employee",
"options": "Employee",
"width": 300
"width": 300,
},
{
"label": _("Employee Name"),
"fieldtype": "data",
"fieldname": "employee_name",
"hidden": 1,
"width": 200
"width": 200,
},
{
"label": _("Timesheet"),
"fieldtype": "Link",
"fieldname": "timesheet",
"options": "Timesheet",
"width": 150
},
{
"label": _("Working Hours"),
"fieldtype": "Float",
"fieldname": "total_hours",
"width": 150
"width": 150,
},
{"label": _("Working Hours"), "fieldtype": "Float", "fieldname": "total_hours", "width": 150},
{
"label": _("Billable Hours"),
"fieldtype": "Float",
"fieldname": "total_billable_hours",
"width": 150
"width": 150,
},
{
"label": _("Billing Amount"),
"fieldtype": "Currency",
"fieldname": "amount",
"width": 150
}
{"label": _("Billing Amount"), "fieldtype": "Currency", "fieldname": "amount", "width": 150},
]
def get_data(filters):
data = []
if(filters.from_date > filters.to_date):
if filters.from_date > filters.to_date:
frappe.msgprint(_("From Date can not be greater than To Date"))
return data
timesheets = get_timesheets(filters)
filters.from_date = frappe.utils.get_datetime(filters.from_date)
filters.to_date = frappe.utils.add_to_date(frappe.utils.get_datetime(filters.to_date), days=1, seconds=-1)
filters.to_date = frappe.utils.add_to_date(
frappe.utils.get_datetime(filters.to_date), days=1, seconds=-1
)
timesheet_details = get_timesheet_details(filters, timesheets.keys())
@@ -88,46 +80,58 @@ def get_data(filters):
total_amount += billing_duration * flt(row.billing_rate)
if total_hours:
data.append({
"employee": timesheets.get(ts).employee,
"employee_name": timesheets.get(ts).employee_name,
"timesheet": ts,
"total_billable_hours": total_billing_hours,
"total_hours": total_hours,
"amount": total_amount
})
data.append(
{
"employee": timesheets.get(ts).employee,
"employee_name": timesheets.get(ts).employee_name,
"timesheet": ts,
"total_billable_hours": total_billing_hours,
"total_hours": total_hours,
"amount": total_amount,
}
)
return data
def get_timesheets(filters):
record_filters = [
["start_date", "<=", filters.to_date],
["end_date", ">=", filters.from_date],
["docstatus", "=", 1]
]
["start_date", "<=", filters.to_date],
["end_date", ">=", filters.from_date],
["docstatus", "=", 1],
]
if "employee" in filters:
record_filters.append(["employee", "=", filters.employee])
timesheets = frappe.get_all("Timesheet", filters=record_filters, fields=["employee", "employee_name", "name"])
timesheets = frappe.get_all(
"Timesheet", filters=record_filters, fields=["employee", "employee_name", "name"]
)
timesheet_map = frappe._dict()
for d in timesheets:
timesheet_map.setdefault(d.name, d)
return timesheet_map
def get_timesheet_details(filters, timesheet_list):
timesheet_details_filter = {
"parent": ["in", timesheet_list]
}
timesheet_details_filter = {"parent": ["in", timesheet_list]}
if "project" in filters:
timesheet_details_filter["project"] = filters.project
timesheet_details = frappe.get_all(
"Timesheet Detail",
filters = timesheet_details_filter,
fields=["from_time", "to_time", "hours", "is_billable", "billing_hours", "billing_rate", "parent"]
filters=timesheet_details_filter,
fields=[
"from_time",
"to_time",
"hours",
"is_billable",
"billing_hours",
"billing_rate",
"parent",
],
)
timesheet_details_map = frappe._dict()
@@ -136,6 +140,7 @@ def get_timesheet_details(filters, timesheet_list):
return timesheet_details_map
def get_billable_and_total_duration(activity, start_time, end_time):
precision = frappe.get_precision("Timesheet Detail", "hours")
activity_duration = time_diff_in_hours(end_time, start_time)