-
-
Notifications
You must be signed in to change notification settings - Fork 821
[19.0][MIG] hr_attendance #5705
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
Open
hbrunn
wants to merge
2
commits into
OCA:19.0
Choose a base branch
from
hbrunn:19.0-hr_attendance
base: 19.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+424
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
33 changes: 33 additions & 0 deletions
33
openupgrade_scripts/scripts/hr_attendance/19.0.2.0/post-migration.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,33 @@ | ||
| # Copyright 2026 Hunki Enterprises BV | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from openupgradelib import openupgrade | ||
|
|
||
| from odoo.fields import Command | ||
|
|
||
| _deleted_xmlids = [ | ||
| "hr_attendance.hr_attendance_overtime_rule_employee_company", | ||
| "hr_attendance.hr_attendance_rule_attendance_officer_overtime_restrict", | ||
| "hr_attendance.hr_attendance_rule_attendance_overtime_admin", | ||
| "hr_attendance.hr_attendance_rule_attendance_overtime_simple_user", | ||
| ] | ||
|
|
||
|
|
||
| def cleanup_hr_attendance_rule_attendance_admin(env): | ||
| """ | ||
| Remove old group from hr_attendance_rule_attendance_admin | ||
| """ | ||
| env.ref("hr_attendance.hr_attendance_rule_attendance_admin").write( | ||
| { | ||
| "groups": [ | ||
| Command.unlink(env.ref("hr_attendance.group_hr_attendance_manager").id) | ||
| ], | ||
| } | ||
| ) | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| openupgrade.load_data(env, "hr_attendance", "19.0.2.0/noupdate_changes.xml") | ||
| cleanup_hr_attendance_rule_attendance_admin(env) | ||
| openupgrade.delete_records_safely_by_xml_id(env, _deleted_xmlids) | ||
215 changes: 215 additions & 0 deletions
215
openupgrade_scripts/scripts/hr_attendance/19.0.2.0/pre-migration.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,215 @@ | ||
| # Copyright 2026 Hunki Enterprises BV | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from openupgradelib import openupgrade | ||
|
|
||
| _renamed_models = [ | ||
| ("hr.attendance.overtime", "hr.attendance.overtime.line"), | ||
| ] | ||
|
|
||
| _renamed_tables = [ | ||
| ("hr_attendance_overtime", "hr_attendance_overtime_line"), | ||
| ] | ||
|
|
||
| _renamed_fields = [ | ||
| ("hr.attendance", "hr_attendance", "in_city", "in_location"), | ||
| ("hr.attendance", "hr_attendance", "out_city", "out_location"), | ||
| ( | ||
| "hr.attendance.overtime.line", | ||
| "hr_attendance_overtime_line", | ||
| "duration_real", | ||
| "manual_duration", | ||
| ), | ||
| ] | ||
|
|
||
| SQL_EMPLOYEE2TZ = """ | ||
| ( | ||
| SELECT | ||
| hr_employee.id employee_id, | ||
| COALESCE( | ||
| MIN(resource_calendar.tz), | ||
| MIN(resource_resource.tz), | ||
| MIN(company_resource_calendar.tz) | ||
| ) zone | ||
| FROM | ||
| hr_employee | ||
| JOIN | ||
| resource_resource | ||
| ON | ||
| hr_employee.resource_id=resource_resource.id | ||
| LEFT JOIN | ||
| resource_calendar | ||
| ON | ||
| resource_resource.calendar_id=resource_calendar.id | ||
| JOIN | ||
| res_company | ||
| ON | ||
| hr_employee.company_id=res_company.id | ||
| LEFT JOIN | ||
| resource_calendar company_resource_calendar | ||
| ON | ||
| res_company.resource_calendar_id=company_resource_calendar.id | ||
| GROUP BY | ||
| hr_employee.id | ||
| ) employee2zone | ||
| """ | ||
|
|
||
|
|
||
| def hr_attendance_date(env): | ||
| """ | ||
| Pre-fill hr.attendance#date | ||
| """ | ||
| openupgrade.add_columns( | ||
| env, [("hr.attendance", "date", "date", None, "hr_attendance")] | ||
| ) | ||
| env.cr.execute( | ||
| f""" | ||
| UPDATE | ||
| hr_attendance | ||
| SET | ||
| date=(check_in AT TIME ZONE COALESCE(employee2zone.zone, 'utc'))::date | ||
| FROM | ||
| {SQL_EMPLOYEE2TZ} | ||
| WHERE | ||
| employee2zone.employee_id=hr_attendance.employee_id | ||
| AND date IS NULL | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| def hr_attendance_overtime_line_fields(env): | ||
| """ | ||
| Pre-fill new fields of hr.attendance.overtime.line | ||
| """ | ||
| openupgrade.add_columns( | ||
| env, | ||
| [ | ||
| ( | ||
| "hr.attendance.overtime.line", | ||
| "status", | ||
| "char", | ||
| "approved", | ||
| "hr_attendance_overtime_line", | ||
| ), | ||
| ( | ||
| "hr.attendance.overtime.line", | ||
| "time_start", | ||
| "datetime", | ||
| None, | ||
| "hr_attendance_overtime_line", | ||
| ), | ||
| ( | ||
| "hr.attendance.overtime.line", | ||
| "time_stop", | ||
| "datetime", | ||
| None, | ||
| "hr_attendance_overtime_line", | ||
| ), | ||
| ], | ||
| ) | ||
| # date is required in v19, fill with create_date if empty, possibly wrong | ||
| env.cr.execute( | ||
| f""" | ||
| UPDATE | ||
| hr_attendance_overtime_line | ||
| SET | ||
| date=( | ||
| create_date AT TIME ZONE COALESCE(employee2zone.zone, 'utc') | ||
| )::date | ||
| FROM | ||
| {SQL_EMPLOYEE2TZ} | ||
| WHERE | ||
| employee2zone.employee_id=hr_attendance_overtime_line.employee_id | ||
| AND | ||
| date IS NULL | ||
| """ | ||
| ) | ||
| # time_start, time_stop need to match some check_in, check_out from hr_attendance | ||
| env.cr.execute( | ||
| """ | ||
| UPDATE | ||
| hr_attendance_overtime_line | ||
| SET | ||
| time_start=hr_attendance.check_in, | ||
| time_stop=hr_attendance.check_out | ||
| FROM | ||
| hr_attendance | ||
| WHERE | ||
| hr_attendance.employee_id=hr_attendance_overtime_line.employee_id | ||
| AND | ||
| hr_attendance.date=hr_attendance_overtime_line.date | ||
| """ | ||
| ) | ||
| # for companies with manager approval, set status from state on attendance | ||
| env.cr.execute( | ||
| """ | ||
| UPDATE | ||
| hr_attendance_overtime_line | ||
| SET | ||
| status=hr_attendance.overtime_status | ||
| FROM | ||
| hr_employee, res_company, hr_attendance | ||
| WHERE | ||
| hr_attendance.check_in=hr_attendance_overtime_line.time_start | ||
| AND | ||
| hr_attendance.employee_id=hr_attendance_overtime_line.employee_id | ||
| AND | ||
| hr_attendance_overtime_line.employee_id=hr_employee.id | ||
| AND | ||
| hr_employee.company_id=res_company.id | ||
| AND | ||
| res_company.attendance_overtime_validation = 'by_manager' | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| def hr_attendance_validated_overtime_hours(env): | ||
| """ | ||
| Pre-fill hr.attendance#validated_overtime_hours | ||
| """ | ||
| openupgrade.add_columns( | ||
| env, | ||
| [ | ||
| ( | ||
| "hr.attendance", | ||
| "validated_overtime_hours", | ||
| "float", | ||
| None, | ||
| "hr_attendance", | ||
| ) | ||
| ], | ||
| ) | ||
| # validated_overtime_hours is the sum of approved overtime lines | ||
| env.cr.execute( | ||
| """ | ||
| UPDATE | ||
| hr_attendance | ||
| SET | ||
| validated_overtime_hours=grouped_overtime_lines.sum_duration | ||
| FROM | ||
| ( | ||
| SELECT | ||
| employee_id, time_start, SUM(manual_duration) sum_duration | ||
| FROM | ||
| hr_attendance_overtime_line | ||
| WHERE | ||
| status='approved' | ||
| GROUP BY | ||
| employee_id, time_start | ||
| ) grouped_overtime_lines | ||
| WHERE | ||
| grouped_overtime_lines.employee_id=hr_attendance.employee_id AND | ||
| grouped_overtime_lines.time_start=hr_attendance.check_in | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| openupgrade.rename_models(env.cr, _renamed_models) | ||
| openupgrade.rename_tables(env.cr, _renamed_tables) | ||
| openupgrade.rename_fields(env, _renamed_fields) | ||
| # order matters | ||
| hr_attendance_date(env) | ||
| hr_attendance_overtime_line_fields(env) | ||
| hr_attendance_validated_overtime_hours(env) |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For letting the record as it's in 19, we should remove the group
hr_attendance.group_hr_attendance_managerfromhr_attendance.hr_attendance_rule_attendance_adminrecord.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done