diff --git a/l10n_us_hr_payroll/migrations/13.0.0.0.1/post-migration.py b/l10n_us_hr_payroll/migrations/13.0.0.0.1/post-migration.py new file mode 100644 index 00000000..406055d7 --- /dev/null +++ b/l10n_us_hr_payroll/migrations/13.0.0.0.1/post-migration.py @@ -0,0 +1,30 @@ +# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details. + +import odoo + + +def migrate(cr, version): + """ + Post-migration no contracts will have any structure types. + Unfortunately, we have no way of knowing if they used USA in the past + so we have to just assume they did (knowing of course that l10n_us_hr_payroll was installed)... + """ + env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {}) + structure_type = env.ref('l10n_us_hr_payroll.structure_type_employee') + cr.execute("UPDATE hr_contract " + "SET structure_type_id = %s " + "WHERE structure_type_id is null AND state in ('draft', 'open')", (structure_type.id, )) + + """ + Additionally, it is known that post-migration databases will have bad + work entry record states (and you will spend time trying to fix them + before you could run a payroll batch). + """ + default_work_entry_type = env.ref('hr_work_entry.work_entry_type_attendance', raise_if_not_found=False) + if default_work_entry_type: + cr.execute("UPDATE hr_work_entry " + "SET work_entry_type_id = %s " + "WHERE work_entry_type_id is null", (default_work_entry_type.id, )) + cr.execute("UPDATE hr_work_entry " + "SET state = 'draft' " + "WHERE state = 'conflict'") diff --git a/l10n_us_hr_payroll/migrations/13.0.0.0.1/pre-migration.py b/l10n_us_hr_payroll/migrations/13.0.0.0.1/pre-migration.py new file mode 100644 index 00000000..e71317a4 --- /dev/null +++ b/l10n_us_hr_payroll/migrations/13.0.0.0.1/pre-migration.py @@ -0,0 +1,26 @@ +# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details. + +import odoo + + +def migrate(cr, version): + """ + Salary Rules can be archived by Odoo S.A. during migration. + This leaves them archived after the migration, and even un-archiving them + is not enough because they will then be pointed to a "migrated" structure. + """ + env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {}) + xml_refs = env['ir.model.data'].search([ + ('module', '=', 'l10n_us_hr_payroll'), + ('model', '=', 'hr.salary.rule'), + ]) + # I don't know why Odoo makes these non-updatable... + xml_refs.write({'noupdate': False}) + + rule_ids = xml_refs.mapped('res_id') + rules = env['hr.salary.rule'].browse(rule_ids) + rules.write({'active': True}) + + # Cannot add new selection type without fixing missing + cr.execute('UPDATE hr_payroll_structure SET schedule_pay = \'monthly\' WHERE schedule_pay is null;') + cr.execute('UPDATE hr_payroll_structure_type SET default_schedule_pay = \'monthly\' WHERE default_schedule_pay is null;') diff --git a/l10n_us_hr_payroll/models/hr_contract.py b/l10n_us_hr_payroll/models/hr_contract.py index 68109908..ab5772c8 100644 --- a/l10n_us_hr_payroll/models/hr_contract.py +++ b/l10n_us_hr_payroll/models/hr_contract.py @@ -6,7 +6,7 @@ from .us_payroll_config import FUTA_TYPE_NORMAL, \ FUTA_TYPE_EXEMPT -class HrPayrollStructure(models.Model): +class HrPayrollStructureType(models.Model): _inherit = 'hr.payroll.structure.type' default_schedule_pay = fields.Selection(selection_add=[('semi-monthly', 'Semi-monthly')])