diff --git a/hr_addon/custom_scripts/custom_python/location.py b/hr_addon/custom_scripts/custom_python/location.py new file mode 100644 index 0000000..c8c40e4 --- /dev/null +++ b/hr_addon/custom_scripts/custom_python/location.py @@ -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() + diff --git a/hr_addon/custom_scripts/custom_python/weekly_working_hours.py b/hr_addon/custom_scripts/custom_python/weekly_working_hours.py index 7cc6cdc..212443c 100644 --- a/hr_addon/custom_scripts/custom_python/weekly_working_hours.py +++ b/hr_addon/custom_scripts/custom_python/weekly_working_hours.py @@ -1,5 +1,5 @@ import frappe -from frappe.utils import getdate +from frappe.utils import today from frappe.model.document import Document @frappe.whitelist() @@ -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 @@ -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() - - diff --git a/hr_addon/hooks.py b/hr_addon/hooks.py index f8e0d13..28a5111 100644 --- a/hr_addon/hooks.py +++ b/hr_addon/hooks.py @@ -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"} @@ -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", - ] } \ No newline at end of file diff --git a/hr_addon/hr_addon/doctype/workday/workday.json b/hr_addon/hr_addon/doctype/workday/workday.json index 7a129e0..6e1b5f9 100644 --- a/hr_addon/hr_addon/doctype/workday/workday.json +++ b/hr_addon/hr_addon/doctype/workday/workday.json @@ -71,14 +71,12 @@ { "fieldname": "number_of_breaks", "fieldtype": "Int", - "hidden": 1, "label": "Number of Breaks", "read_only": 1 }, { "fieldname": "break_hours", "fieldtype": "Float", - "hidden": 1, "label": "Break Hours", "read_only": 1 }, @@ -165,10 +163,11 @@ } ], "links": [], - "modified": "2023-05-09 08:59:25.570460", + "modified": "2024-07-24 10:53:25.862087", "modified_by": "Administrator", "module": "HR Addon", "name": "Workday", + "naming_rule": "Expression", "owner": "Administrator", "permissions": [ { @@ -197,5 +196,6 @@ } ], "sort_field": "modified", - "sort_order": "DESC" + "sort_order": "DESC", + "states": [] } \ No newline at end of file diff --git a/hr_addon/patches.txt b/hr_addon/patches.txt index 576c225..b4c0032 100644 --- a/hr_addon/patches.txt +++ b/hr_addon/patches.txt @@ -1 +1,3 @@ -hr_addon.patches.v15_0.add_custom_field_for_employee \ No newline at end of file +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 #1 \ No newline at end of file diff --git a/hr_addon/patches/v15_0/add_custom_field_for_hr_settings.py b/hr_addon/patches/v15_0/add_custom_field_for_hr_settings.py new file mode 100644 index 0000000..41175e6 --- /dev/null +++ b/hr_addon/patches/v15_0/add_custom_field_for_hr_settings.py @@ -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." + ) + ) + + \ No newline at end of file diff --git a/hr_addon/patches/v15_0/add_custom_field_for_location.py b/hr_addon/patches/v15_0/add_custom_field_for_location.py new file mode 100644 index 0000000..b187083 --- /dev/null +++ b/hr_addon/patches/v15_0/add_custom_field_for_location.py @@ -0,0 +1,13 @@ +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") + + create_custom_field("Location", + dict(fieldname="qr_code_url", label="QR Code URL", + fieldtype="Data", insert_after="location",read_only=1 + ) + ) diff --git a/hr_addon/public/js/employee_checkin.js b/hr_addon/public/js/employee_checkin.js new file mode 100644 index 0000000..6006bdb --- /dev/null +++ b/hr_addon/public/js/employee_checkin.js @@ -0,0 +1,12 @@ +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); + } + }); + } + } + }); + \ No newline at end of file diff --git a/hr_addon/public/js/hr_settings.js b/hr_addon/public/js/hr_settings.js new file mode 100644 index 0000000..59a687e --- /dev/null +++ b/hr_addon/public/js/hr_settings.js @@ -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") + } + } + }); + +}); \ No newline at end of file diff --git a/hr_addon/public/js/list_view.js b/hr_addon/public/js/list_view.js index 49a7881..cd2da34 100644 --- a/hr_addon/public/js/list_view.js +++ b/hr_addon/public/js/list_view.js @@ -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(); - }); - - }, + };