Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions hr_addon/custom_scripts/custom_python/employee_checkin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import qrcode
import frappe
from frappe.utils import get_url_to_form
from frappe import _

29 changes: 29 additions & 0 deletions hr_addon/custom_scripts/custom_python/location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import qrcode
import frappe
from frappe.utils import get_url_to_form

def generate_qr_code_for_location(doc, method):
location_name = doc.name
# Properly format the URL with the location parameter
base_url = frappe.utils.get_url()
qr_code_content = f"{base_url}/app/employee-checkin/new?device_id={location_name}"
img = qrcode.make(qr_code_content)
file_name = frappe.generate_hash("", 10)
file_path = frappe.get_site_path("public", "files", f"{file_name}.png")
img.save(file_path)

qr_code_url = f"/files/{file_name}.png"

# Update the document with the QR code URL
doc.db_set("qr_code_url", qr_code_url)

# Attach the QR code to the Location document
frappe.get_doc({
"doctype": "File",
"file_url": qr_code_url,
"attached_to_name": doc.name,
"attached_to_doctype": doc.doctype,
"file_name": f"{location_name}_qr_code.png",
"folder": "Home/Attachments"
}).insert()

11 changes: 7 additions & 4 deletions hr_addon/custom_scripts/custom_python/weekly_working_hours.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import frappe
from frappe.utils import getdate
from frappe.utils import today
from frappe.model.document import Document

@frappe.whitelist()
Expand All @@ -17,6 +17,9 @@ def set_from_to_dates():
year_start_date = fiscal_year[0].year_start_date
year_end_date = fiscal_year[0].year_end_date

# Get today's date
current_date = today()

# Update the valid_from and valid_to fields
frappe.db.sql("""
UPDATE
Expand All @@ -33,11 +36,11 @@ def set_from_to_dates():
WHERE
permanent = 1
)
AND creation BETWEEN %(year_start_date)s AND %(year_end_date)s
""", {
"year_start_date": year_start_date,
"year_end_date": year_end_date
"year_end_date": year_end_date,
"current_date": current_date
})

frappe.db.commit()


14 changes: 7 additions & 7 deletions hr_addon/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
# include js in page
# page_js = {"page" : "public/js/file.js"}
doctype_js = {

"HR Settings": "public/js/hr_settings.js",
"Employee Checkin": "public/js/employee_checkin.js",

}
# include js in doctype views
# doctype_js = {"doctype" : "public/js/doctype.js"}
Expand Down Expand Up @@ -196,16 +198,14 @@
"Leave Application": {
"on_change": "hr_addon.hr_addon.api.export_calendar.export_calendar",
"on_cancel": "hr_addon.hr_addon.api.export_calendar.export_calendar"
}
},
"Location": {
"after_insert": "hr_addon.custom_scripts.custom_python.location.generate_qr_code_for_location",
},
}

doctype_list_js = {"Weekly Working Hours" : "public/js/list_view.js"}

scheduler_events = {
"hourly": [
"hr_addon.hr_addon.doctype.hr_addon_settings.hr_addon_settings.generate_workdays_scheduled_job"
],
"yearly": [
"hr_addon.custom_scripts.custom_python.weekly_working_hours.set_from_to_dates",
]
}
4 changes: 3 additions & 1 deletion hr_addon/patches.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
hr_addon.patches.v15_0.add_custom_field_for_employee
hr_addon.patches.v15_0.add_custom_field_for_employee
hr_addon.patches.v15_0.add_custom_field_for_hr_settings #12
hr_addon.patches.v15_0.add_custom_field_for_location #1234
21 changes: 21 additions & 0 deletions hr_addon/patches/v15_0/add_custom_field_for_hr_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import frappe
from frappe.custom.doctype.custom_field.custom_field import create_custom_field
from frappe.custom.doctype.property_setter.property_setter import make_property_setter

def execute():

frappe.reload_doc("HR", "doctype", "HR Settings")

create_custom_field("HR Settings",
dict(fieldname="danger_zone_section", label="\u26a0\ufe0f Danger Zone \u26a0\ufe0f",
fieldtype="Section Break", insert_after="allow_employee_checkin_from_mobile_app",
)
)

create_custom_field("HR Settings",
dict(fieldname="update_year", label="Update Year",
fieldtype="Button", insert_after="danger_zone_section",description="Clicking this button will retrieve the current fiscal year and update the 'From' and 'To' year fields for Weekly Working Hours records created this year."
)
)


17 changes: 17 additions & 0 deletions hr_addon/patches/v15_0/add_custom_field_for_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import frappe
from frappe.custom.doctype.custom_field.custom_field import create_custom_field
from frappe.custom.doctype.property_setter.property_setter import make_property_setter

def execute():

frappe.reload_doc("Assets", "doctype", "Location")
frappe.reload_doc("HR", "doctype", "employee_checkin")


create_custom_field("Location",
dict(fieldname="qr_code_url", label="QR Code URL",
fieldtype="Data", insert_after="location",read_only=1
)
)

make_property_setter("Employee Checkin", "device_id", "depends_on",'',"Data")
16 changes: 16 additions & 0 deletions hr_addon/public/js/employee_checkin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
frappe.ui.form.on('Employee Checkin', {
onload(frm) {
if (frm.is_new()) {
frappe.db.get_value("Employee", {"user_id": frappe.session.user}, "name", function(value) {
if (value) {
frm.set_value('employee', value.name);
}
});
}

const hasHRRole = frappe.user.has_role("HR User") || frappe.user.has_role("HR Manager");
if (!hasHRRole) {
frm.set_df_property('device_id', 'hidden', 1);
}
}
});
19 changes: 19 additions & 0 deletions hr_addon/public/js/hr_settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2024, Phamos GmbH and contributors
// For license information, please see license.txt

frappe.ui.form.on('HR Settings', 'update_year', function(frm) {
console.log('update year')
frappe.call({
method: "hr_addon.custom_scripts.custom_python.weekly_working_hours.set_from_to_dates",
args: {},
callback(r) {
if(!r.exc){
frappe.msgprint("Weekly working hours for permanent employees have been successfully updated.")
}
else{
frappe.msgprint("Error occured while updating weekly working hours")
}
}
});

});
14 changes: 1 addition & 13 deletions hr_addon/public/js/list_view.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
frappe.provide("hr_addon.frappe.views");
frappe.listview_settings["Weekly Working Hours"] = {
onload: function (list_view) {

list_view.page.add_button(__("Update Year"), function () {
frappe.call({
method: "hr_addon.custom_scripts.custom_python.weekly_working_hours.set_from_to_dates",
args: {},
callback(r) {}
});
window.location.reload();
});

},

};