From 137b1f4bc208e362a914c0ccfb62c4a274df4a43 Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Sun, 21 Mar 2021 13:35:09 -0700 Subject: [PATCH] [FIX] hr_payroll_timesheet: Fixes for a database that has gone through multiple Odoo Upgrades Init will run on install, even if the module existed in the prior version. Because these init scripts are intended to clear (and maybe even re-name back on actual init of data), records we should be more generic with the intended name. Additionally, if your database already had `hr_payroll_timesheet` based 'TS' work entry codes, then we cannot delete it if it is used on records like payslips (as a work type). Delete the link to simply stop using the old record, but leave it behind to keep it working. --- hr_payroll_attendance/__init__.py | 2 +- hr_payroll_timesheet/__init__.py | 2 +- .../migrations/14.0.0.0.1/pre-migration.py | 19 +++++++++++++++++++ hr_timesheet_work_entry/__init__.py | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 hr_payroll_timesheet/migrations/14.0.0.0.1/pre-migration.py diff --git a/hr_payroll_attendance/__init__.py b/hr_payroll_attendance/__init__.py index a366a01b..d3b52674 100755 --- a/hr_payroll_attendance/__init__.py +++ b/hr_payroll_attendance/__init__.py @@ -10,6 +10,6 @@ def attn_payroll_pre_init_hook(cr): from installing. """ cr.execute("UPDATE hr_work_entry_type " - "SET code = 'ATTN_OT-PRE-INSTALL' " + "SET code = 'ATTN_OT-PRE-INSTALL-14' " "WHERE code = 'ATTN_OT';" ) diff --git a/hr_payroll_timesheet/__init__.py b/hr_payroll_timesheet/__init__.py index 90502662..73e9c28d 100644 --- a/hr_payroll_timesheet/__init__.py +++ b/hr_payroll_timesheet/__init__.py @@ -10,6 +10,6 @@ def ts_payroll_pre_init_hook(cr): from installing. """ cr.execute("UPDATE hr_work_entry_type " - "SET code = 'TS_OT-PRE-INSTALL' " + "SET code = 'TS_OT-PRE-INSTALL-14' " "WHERE code = 'TS_OT';" ) diff --git a/hr_payroll_timesheet/migrations/14.0.0.0.1/pre-migration.py b/hr_payroll_timesheet/migrations/14.0.0.0.1/pre-migration.py new file mode 100644 index 00000000..b4d0ae4a --- /dev/null +++ b/hr_payroll_timesheet/migrations/14.0.0.0.1/pre-migration.py @@ -0,0 +1,19 @@ +# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details. + +import odoo + + +def migrate(cr, version): + """ + In 13.0, we had our own work type: + hr_payroll_timesheet.work_input_timesheet + + This was moved to `hr_timesheet_work_entry` + We will unlink the XML ref so that the record will be kept. + """ + env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {}) + xml_refs = env['ir.model.data'].search([ + ('module', '=', 'hr_payroll_timesheet'), + ('name', '=', 'work_input_timesheet'), + ]) + xml_refs.unlink() diff --git a/hr_timesheet_work_entry/__init__.py b/hr_timesheet_work_entry/__init__.py index 6e8e0aba..e58c8b0b 100644 --- a/hr_timesheet_work_entry/__init__.py +++ b/hr_timesheet_work_entry/__init__.py @@ -10,6 +10,6 @@ def ts_work_type_pre_init_hook(cr): from installing. """ cr.execute("UPDATE hr_work_entry_type " - "SET code = 'TS-PRE-INSTALL' " + "SET code = 'TS-PRE-INSTALL-14' " "WHERE code = 'TS';" )