-
-
Notifications
You must be signed in to change notification settings - Fork 785
[17.0][OU-ADD] hr_holidays: Migration to 17.0 #4702
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
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
44 changes: 44 additions & 0 deletions
44
openupgrade_scripts/scripts/hr_holidays/17.0.1.6/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,44 @@ | ||
| # Copyright 2024- Le Filament (https://le-filament.com) | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from openupgradelib import openupgrade | ||
|
|
||
|
|
||
| def _leave_type_responsible_convert_field_m2o_to_m2m(env): | ||
| # Convert m2o to m2m in 'onboarding.onboarding.step' | ||
| openupgrade.m2o_to_x2m( | ||
| env.cr, | ||
| env["hr.leave.type"], | ||
| "hr_leave_type", | ||
| "responsible_ids", | ||
| "responsible_id", | ||
| ) | ||
|
|
||
|
|
||
| def _compute_already_accrued(env): | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| UPDATE hr_leave_allocation | ||
| SET already_accrued = True | ||
| WHERE allocation_type = 'accrual' | ||
| AND state = 'validate' | ||
| AND accrual_plan_id IS NOT NULL | ||
| AND employee_id IS NOT NULL | ||
| AND number_of_days > 0; | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| openupgrade.load_data(env, "hr_holidays", "17.0.1.6/noupdate_changes.xml") | ||
| _leave_type_responsible_convert_field_m2o_to_m2m(env) | ||
| _compute_already_accrued(env) | ||
| openupgrade.delete_records_safely_by_xml_id( | ||
| env, | ||
| [ | ||
| "hr_holidays.mail_act_leave_allocation_second_approval", | ||
| "hr_holidays.hr_leave_stress_day_rule_multi_company", | ||
| ], | ||
| ) |
154 changes: 154 additions & 0 deletions
154
openupgrade_scripts/scripts/hr_holidays/17.0.1.6/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,154 @@ | ||
| # Copyright 2024- Le Filament (https://le-filament.com) | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
| from openupgradelib import openupgrade | ||
|
|
||
| _model_renames = [ | ||
| ("hr.leave.stress.day", "hr.leave.mandatory.day"), | ||
| ] | ||
|
|
||
| _table_renames = [ | ||
| ("hr_leave_stress_day", "hr_leave_mandatory_day"), | ||
| ] | ||
|
|
||
|
|
||
| def _pre_create_accrual_plan_active(cr): | ||
| """ | ||
| Precreate column with default value true, then remove default from SQL | ||
| """ | ||
| openupgrade.logged_query( | ||
| cr, | ||
| """ | ||
| ALTER TABLE hr_leave_accrual_plan ADD COLUMN active boolean DEFAULT true | ||
| """, | ||
| ) | ||
| openupgrade.logged_query( | ||
| cr, | ||
| """ | ||
| ALTER TABLE hr_leave_accrual_plan ALTER COLUMN active DROP DEFAULT | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| def _hr_leave_company_id(cr): | ||
| """Create and set company_id value in the same order than new compute | ||
| (employee_company_id, mode_company_id, department_id.company_id) | ||
| """ | ||
| openupgrade.logged_query( | ||
| cr, | ||
| """ | ||
| ALTER TABLE hr_leave | ||
| ADD COLUMN IF NOT EXISTS company_id INTEGER; | ||
| """, | ||
| ) | ||
| openupgrade.logged_query( | ||
| cr, | ||
| """UPDATE hr_leave AS leave | ||
| SET company_id = CASE | ||
| WHEN employee_company_id IS NOT NULL THEN employee_company_id | ||
| WHEN mode_company_id IS NOT NULL THEN mode_company_id | ||
| ELSE NULL | ||
| END | ||
| WHERE leave.company_id IS NULL""", | ||
| ) | ||
| openupgrade.logged_query( | ||
| cr, | ||
| """UPDATE hr_leave AS leave | ||
| SET company_id = d.company_id | ||
| FROM hr_department AS d | ||
| WHERE leave.company_id IS NULL AND leave.department_id = d.id""", | ||
| ) | ||
|
|
||
|
|
||
| def _map_leave_accrual_level_action(cr): | ||
| openupgrade.logged_query( | ||
| cr, | ||
| """ | ||
| UPDATE hr_leave_accrual_level | ||
| SET action_with_unused_accruals = CASE | ||
| WHEN maximum_leave > 0 AND postpone_max_days > 0 THEN 'maximum' | ||
| ELSE 'all' | ||
| END | ||
| WHERE action_with_unused_accruals = 'postponed'; | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| def _map_leave_accrual_level_added_value_type(cr): | ||
| openupgrade.logged_query( | ||
| cr, | ||
| """ | ||
| UPDATE hr_leave_accrual_level | ||
| SET added_value_type = 'day' | ||
| WHERE added_value_type = 'days'; | ||
| """, | ||
| ) | ||
| openupgrade.logged_query( | ||
| cr, | ||
| """ | ||
| UPDATE hr_leave_accrual_level | ||
| SET added_value_type = 'hour' | ||
| WHERE added_value_type = 'hours'; | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| def _map_leave_allocation_state(cr): | ||
| openupgrade.logged_query( | ||
| cr, | ||
| """ | ||
| UPDATE hr_leave_allocation | ||
| SET state = 'confirm' | ||
| WHERE state = 'draft'; | ||
| """, | ||
| ) | ||
| openupgrade.logged_query( | ||
| cr, | ||
| """ | ||
| UPDATE hr_leave_allocation | ||
| SET state = 'refuse' | ||
| WHERE state = 'cancel'; | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| def _set_is_based_on_worked_time(cr): | ||
| openupgrade.logged_query( | ||
| cr, | ||
| """ | ||
| ALTER TABLE hr_leave_accrual_plan | ||
| ADD COLUMN IF NOT EXISTS is_based_on_worked_time BOOLEAN; | ||
| """, | ||
| ) | ||
| openupgrade.logged_query( | ||
| cr, | ||
| """ | ||
| UPDATE hr_leave_accrual_plan plan | ||
| SET is_based_on_worked_time = subquery.max_value::BOOLEAN | ||
| FROM ( | ||
| SELECT accrual_plan_id, MAX(is_based_on_worked_time::INT) AS max_value | ||
| FROM hr_leave_accrual_level | ||
| GROUP BY accrual_plan_id | ||
| ) subquery | ||
| WHERE subquery.accrual_plan_id = plan.id; | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| def _delete_sql_constraints(env): | ||
| # Delete constraints to recreate it | ||
| openupgrade.delete_sql_constraint_safely( | ||
| env, "hr_holidays", "hr_leave_accrual_level", "check_dates" | ||
| ) | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| openupgrade.rename_models(env.cr, _model_renames) | ||
| openupgrade.rename_tables(env.cr, _table_renames) | ||
| _pre_create_accrual_plan_active(env.cr) | ||
| _hr_leave_company_id(env.cr) | ||
| _map_leave_accrual_level_action(env.cr) | ||
| _map_leave_accrual_level_added_value_type(env.cr) | ||
| _map_leave_allocation_state(env.cr) | ||
| _set_is_based_on_worked_time(env.cr) | ||
| _delete_sql_constraints(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.
Uh oh!
There was an error while loading. Please reload this page.