-
Notifications
You must be signed in to change notification settings - Fork 2
fix(Employee): move Expected Daily Working Time to child table (DRC-148) #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9c27625
fix(Employee): move Expected Daily Working Time to child table (DRC-148)
PatrickDEissler 04434e0
feat: validate expected_working_hours (Date Of Joining shall be min v…
PatrickDEissler 1ec0fc9
feat: add utility function get_expected_working_hours
PatrickDEissler 0b964f2
Merge branch 'version-15' into drc-148-2
barredterra b07fc15
Merge branch 'version-15' into drc-148-2
PatrickDEissler 4cd5640
fix: use getdate for valid_from
PatrickDEissler 3cc2ad2
chore: favor tuples over lists
PatrickDEissler 871618a
refactor: general refactoring in patch
PatrickDEissler 6383109
fix: remove typos and further refactor
PatrickDEissler a649427
chore: run patches for Custom Fields and Property Setters independently
PatrickDEissler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
time_capture/patches/move_expected_working_time_to_child_table.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import frappe | ||
|
|
||
|
|
||
| def execute(): | ||
| custom_field_filters = { | ||
| "dt": "Employee", | ||
| "fieldname": "expected_daily_working_hours", | ||
| "fieldtype": "Float", | ||
| } | ||
| if not frappe.db.exists("Custom Field", custom_field_filters): | ||
| return | ||
|
|
||
| for employee_id in frappe.get_all( | ||
| "Employee", filters={"expected_daily_working_hours": ("is", "set")}, pluck="name" | ||
| ): | ||
| print(f"Updating {employee_id}") | ||
|
|
||
| employee = frappe.get_doc("Employee", employee_id) | ||
| if employee.expected_working_hours or not employee.expected_daily_working_hours: | ||
| continue | ||
|
|
||
| employee.append( | ||
| "expected_working_hours", | ||
| { | ||
| "valid_from": employee.date_of_joining, | ||
| "expected_daily_working_hours": employee.expected_daily_working_hours, | ||
| }, | ||
| ) | ||
| employee.save() | ||
| frappe.db.delete("Custom Field", custom_field_filters) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import frappe | ||
| from frappe import _ | ||
| from frappe.utils import getdate | ||
|
|
||
|
|
||
| def before_validate(doc, method): | ||
| validate_expected_working_hours(doc) | ||
|
|
||
|
|
||
| def validate_expected_working_hours(doc): | ||
| if not doc.date_of_joining == min(getdate(ewh.valid_from) for ewh in doc.expected_working_hours): | ||
| frappe.throw(_("Date of Joining is not the same as the earliest date of Expected Working Hours.")) | ||
|
|
||
|
|
||
| def get_expected_working_hours(employee_id, date): | ||
| """ | ||
| Get the expected working hours for an employee on a specific date. | ||
| """ | ||
| return frappe.db.get_value( | ||
| "Employee Expected Working Hours", | ||
| filters={"parent": employee_id, "valid_from": ("<=", date)}, | ||
| fieldname="expected_daily_working_hours", | ||
| order_by="valid_from desc", | ||
| ) |
Empty file.
45 changes: 45 additions & 0 deletions
45
...time_capture/doctype/employee_expected_working_hours/employee_expected_working_hours.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| { | ||
| "actions": [], | ||
| "allow_rename": 1, | ||
| "creation": "2025-05-14 14:56:54.878019", | ||
| "doctype": "DocType", | ||
| "editable_grid": 1, | ||
| "engine": "InnoDB", | ||
| "field_order": [ | ||
| "valid_from", | ||
| "expected_daily_working_hours" | ||
| ], | ||
| "fields": [ | ||
| { | ||
| "columns": 4, | ||
| "fieldname": "valid_from", | ||
| "fieldtype": "Date", | ||
| "in_list_view": 1, | ||
| "label": "Valid From", | ||
| "reqd": 1 | ||
| }, | ||
| { | ||
| "columns": 6, | ||
| "fieldname": "expected_daily_working_hours", | ||
| "fieldtype": "Float", | ||
| "in_list_view": 1, | ||
| "label": "Expected Daily Working Hours", | ||
| "non_negative": 1, | ||
| "reqd": 1 | ||
| } | ||
| ], | ||
| "grid_page_length": 50, | ||
| "index_web_pages_for_search": 1, | ||
| "istable": 1, | ||
| "links": [], | ||
| "modified": "2025-05-14 15:44:30.974078", | ||
| "modified_by": "Administrator", | ||
| "module": "Time Capture", | ||
| "name": "Employee Expected Working Hours", | ||
| "owner": "Administrator", | ||
| "permissions": [], | ||
| "row_format": "Dynamic", | ||
| "sort_field": "modified", | ||
| "sort_order": "DESC", | ||
| "states": [] | ||
| } |
9 changes: 9 additions & 0 deletions
9
...e/time_capture/doctype/employee_expected_working_hours/employee_expected_working_hours.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Copyright (c) 2025, ALYF GmbH and contributors | ||
| # For license information, please see license.txt | ||
|
|
||
| # import frappe | ||
| from frappe.model.document import Document | ||
|
|
||
|
|
||
| class EmployeeExpectedWorkingHours(Document): | ||
| pass |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.