Skip to content

Commit

Permalink
Merge pull request #767 from frappe/version-14-hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchamahabal committed Aug 4, 2023
2 parents 405a424 + 12ed4da commit 16ef5ca
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 72 deletions.
53 changes: 32 additions & 21 deletions hrms/hr/doctype/shift_assignment/shift_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ def has_overlapping_timings(shift_1: str, shift_2: str) -> bool:

@frappe.whitelist()
def get_events(start, end, filters=None):
from frappe.desk.calendar import get_event_conditions

employee = frappe.db.get_value(
"Employee", {"user_id": frappe.session.user}, ["name", "company"], as_dict=True
)
Expand All @@ -128,27 +126,32 @@ def get_events(start, end, filters=None):
employee = ""
company = frappe.db.get_value("Global Defaults", None, "default_company")

conditions = get_event_conditions("Shift Assignment", filters)
events = add_assignments(start, end, conditions=conditions)
events = add_assignments(start, end, filters)
return events


def add_assignments(start, end, conditions=None):
events = []
def add_assignments(start, end, filters):
import json

query = """select name, start_date, end_date, employee_name,
employee, docstatus, shift_type
from `tabShift Assignment` where
(
start_date >= %(start_date)s
or end_date <= %(end_date)s
or (%(start_date)s between start_date and end_date and %(end_date)s between start_date and end_date)
)
and docstatus = 1"""
if conditions:
query += conditions
events = []
if isinstance(filters, str):
filters = json.loads(filters)
filters.extend([["start_date", ">=", start], ["end_date", "<=", end], ["docstatus", "=", 1]])

records = frappe.get_list(
"Shift Assignment",
filters=filters,
fields=[
"name",
"start_date",
"end_date",
"employee_name",
"employee",
"docstatus",
"shift_type",
],
)

records = frappe.db.sql(query, {"start_date": start, "end_date": end}, as_dict=True)
shift_timing_map = get_shift_type_timing([d.shift_type for d in records])

for d in records:
Expand Down Expand Up @@ -182,7 +185,9 @@ def add_assignments(start, end, conditions=None):
def get_shift_type_timing(shift_types):
shift_timing_map = {}
data = frappe.get_all(
"Shift Type", filters={"name": ("IN", shift_types)}, fields=["name", "start_time", "end_time"]
"Shift Type",
filters={"name": ("IN", shift_types)},
fields=["name", "start_time", "end_time"],
)

for d in data:
Expand Down Expand Up @@ -364,7 +369,10 @@ def get_prev_or_next_shift(
if date[1] and date[1] < for_timestamp.date():
continue
shift_details = get_employee_shift(
employee, datetime.combine(date[0], for_timestamp.time()), consider_default_shift, None
employee,
datetime.combine(date[0], for_timestamp.time()),
consider_default_shift,
None,
)
if shift_details:
break
Expand All @@ -384,7 +392,10 @@ def get_employee_shift_timings(
curr_shift = get_employee_shift(employee, for_timestamp, consider_default_shift, "forward")
if curr_shift:
next_shift = get_employee_shift(
employee, curr_shift.start_datetime + timedelta(days=1), consider_default_shift, "forward"
employee,
curr_shift.start_datetime + timedelta(days=1),
consider_default_shift,
"forward",
)
prev_shift = get_employee_shift(
employee,
Expand Down
9 changes: 6 additions & 3 deletions hrms/hr/doctype/vehicle_service/vehicle_service.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actions": [],
"creation": "2016-09-03 19:20:14.561962",
"doctype": "DocType",
"document_type": "Document",
Expand All @@ -13,10 +14,10 @@
"fields": [
{
"fieldname": "service_item",
"fieldtype": "Select",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Service Item",
"options": "\nBrake Oil\nBrake Pad\nClutch Plate\nEngine Oil\nOil Change\nWheels",
"options": "Vehicle Service Item",
"reqd": 1
},
{
Expand Down Expand Up @@ -44,7 +45,8 @@
}
],
"istable": 1,
"modified": "2020-03-18 16:49:46.645004",
"links": [],
"modified": "2023-08-02 18:17:19.625251",
"modified_by": "Administrator",
"module": "HR",
"name": "Vehicle Service",
Expand All @@ -53,5 +55,6 @@
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt

# import frappe
from frappe.tests.utils import FrappeTestCase


class TestVehicleServiceItem(FrappeTestCase):
pass
8 changes: 8 additions & 0 deletions hrms/hr/doctype/vehicle_service_item/vehicle_service_item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt

frappe.ui.form.on('Vehicle Service Item', {
// refresh: function(frm) {

// }
});
50 changes: 50 additions & 0 deletions hrms/hr/doctype/vehicle_service_item/vehicle_service_item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "field:service_item",
"creation": "2023-08-02 18:01:01.161734",
"default_view": "List",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"service_item"
],
"fields": [
{
"allow_in_quick_entry": 1,
"fieldname": "service_item",
"fieldtype": "Data",
"in_filter": 1,
"in_list_view": 1,
"label": "Service Item",
"reqd": 1,
"unique": 1
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-08-02 18:01:01.161734",
"modified_by": "Administrator",
"module": "HR",
"name": "Vehicle Service Item",
"naming_rule": "By fieldname",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
9 changes: 9 additions & 0 deletions hrms/hr/doctype/vehicle_service_item/vehicle_service_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

# import frappe
from frappe.model.document import Document


class VehicleServiceItem(Document):
pass
Loading

0 comments on commit 16ef5ca

Please sign in to comment.