-
-
Notifications
You must be signed in to change notification settings - Fork 784
[18.0][OU-ADD] hr_holidays #5260
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
Conversation
openupgrade_scripts/scripts/hr_holidays/18.0.1.6/upgrade_analysis_work.txt
Outdated
Show resolved
Hide resolved
|
/ocabot migration hr_holidays |
b23f267 to
968e4f7
Compare
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
|
Previous comments looks very much like text generated by artificial stupidity... |
968e4f7 to
d8d41e2
Compare
| # DONE: pre-migration: officer -> hr, no -> no_validation | ||
|
|
||
| hr_holidays / hr.leave.type / include_public_holidays_in_duration (boolean): NEW hasdefault: default | ||
| # NOTHING TO DO: new feature |
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.
Need to consider whether we should do something due to https://github.com/OCA/hr-holidays/tree/18.0/hr_holidays_public/
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.
In fact, "considering hr_holidays_public" is outside this PR. So, if somebody want to analyze compatibilities, feel free.
acb94fb to
a566ec0
Compare
a566ec0 to
c7be1e5
Compare
| def split_employee_leaves(env): | ||
| for table in ["hr_leave", "hr_leave_allocation"]: | ||
| env.cr.execute( | ||
| f""" | ||
| SELECT column_name | ||
| FROM information_schema.columns | ||
| WHERE table_name = '{table}' | ||
| """ | ||
| ) | ||
| columns = ", ".join( | ||
| [x[0] for x in env.cr.fetchall() if x[0] not in ("id", "employee_id")] | ||
| ) | ||
| leave_employees = [] | ||
| # case multi_employee | ||
| env.cr.execute( | ||
| f""" | ||
| SELECT leave.id, 'employee', array_agg(rel.hr_employee_id) as employee_ids | ||
| FROM {table} AS leave | ||
| JOIN hr_employee_{table}_rel rel ON rel.{table}_id = leave.id | ||
| WHERE leave.holiday_type = 'employee' AND leave.multi_employee | ||
| GROUP BY leave.id | ||
| """ | ||
| ) | ||
| leave_employees.extend(env.cr.fetchall()) | ||
| # case company | ||
| env.cr.execute( | ||
| f""" | ||
| SELECT leave.id, 'company', array_agg(he.id) as employee_ids | ||
| FROM {table} AS leave | ||
| JOIN hr_employee he ON he.company_id = leave.mode_company_id | ||
| WHERE leave.holiday_type = 'company' | ||
| GROUP BY leave.id | ||
| """ | ||
| ) | ||
| leave_employees.extend(env.cr.fetchall()) | ||
| # case category | ||
| env.cr.execute( | ||
| f""" | ||
| SELECT leave.id, 'category', array_agg(rel.employee_id) as employee_ids | ||
| FROM {table} AS leave | ||
| JOIN employee_category_rel rel ON rel.category_id = leave.category_id | ||
| WHERE leave.holiday_type = 'category' | ||
| GROUP BY leave.id | ||
| """ | ||
| ) | ||
| leave_employees.extend(env.cr.fetchall()) | ||
| # case department | ||
| env.cr.execute( | ||
| f""" | ||
| SELECT leave.id, 'department', array_agg(he.id) as employee_ids | ||
| FROM {table} AS leave | ||
| JOIN hr_employee he ON he.department_id = leave.department_id | ||
| WHERE leave.holiday_type = 'department' | ||
| GROUP BY leave.id | ||
| """ | ||
| ) | ||
| leave_employees.extend(env.cr.fetchall()) | ||
| for table_id, holiday_type, employee_ids in leave_employees: | ||
| employees = env["hr.employee"].browse(employee_ids) | ||
| if employee_ids: | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| f""" | ||
| UPDATE {table} | ||
| SET employee_id = {employees[0].id} | ||
| WHERE id = {table_id} | ||
| """, | ||
| ) | ||
| if holiday_type != "employee": | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| f""" | ||
| UPDATE {table} | ||
| SET holiday_type = 'employee' | ||
| WHERE id = {table_id} | ||
| """, | ||
| ) | ||
| for employee in employees[1:]: | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| f""" | ||
| INSERT INTO {table} (employee_id, {columns}) | ||
| SELECT {employee.id}, {columns} | ||
| FROM {table} | ||
| WHERE id = {table_id} | ||
| """, | ||
| ) | ||
| else: | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| f""" | ||
| DELETE FROM {table} WHERE id = {table_id} | ||
| """, | ||
| ) |
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.
Hi @MiquelRForgeFlow are you sure about that one ?
On my database, everytime I had a leave or allocation concerning multiple employees, individuals leave or allocations were also created for each one of these.
Now running migration on my database, I end up with duplicate leave and allocations (even worse when I had allocation for company, it created allocations for employees which are not anymore under contract for years).
Maybe we should do that only for leave / allocation which are in draft state only ?
Supersedes #5023.