diff --git a/addons/hr/__init__.py b/addons/hr/__init__.py index c4a614ab8cb..71d0cc322e7 100644 --- a/addons/hr/__init__.py +++ b/addons/hr/__init__.py @@ -1,6 +1,19 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from odoo import api, fields, SUPERUSER_ID + from . import models from . import wizard from . import populate + + +def _install_hr_localization(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + if any(c.partner_id.country_id.code == 'MX' for c in env['res.company'].search([])): + l10n_mx = env['ir.module.module'].sudo().search([ + ('name', '=', 'l10n_mx_hr'), + ('state', 'not in', ['installed', 'to install', 'to upgrade']), + ]) + if l10n_mx: + l10n_mx.button_immediate_install() diff --git a/addons/hr/__manifest__.py b/addons/hr/__manifest__.py index 8ccb7b0a874..62beb9d34f7 100644 --- a/addons/hr/__manifest__.py +++ b/addons/hr/__manifest__.py @@ -46,6 +46,7 @@ ], 'installable': True, 'application': True, + 'post_init_hook': '_install_hr_localization', 'assets': { 'mail.assets_messaging': [ 'hr/static/src/models/*.js', diff --git a/addons/hr/models/res_company.py b/addons/hr/models/res_company.py index d833b2a1c60..cd1937d639e 100644 --- a/addons/hr/models/res_company.py +++ b/addons/hr/models/res_company.py @@ -9,23 +9,3 @@ class Company(models.Model): hr_presence_control_email_amount = fields.Integer(string="# emails to send") hr_presence_control_ip_list = fields.Char(string="Valid IP addresses") - - def _install_hr_localizations(self): - if any(c.partner_id.country_id.code == 'MX' for c in self): - l10n_mx = self.env['ir.module.module'].sudo().search([ - ('name', '=', 'l10n_mx_hr'), - ('state', 'not in', ['installed', 'to install', 'to upgrade']), - ]) - if l10n_mx: - l10n_mx.button_immediate_install() - - def create(self, vals_list): - res = super().create(vals_list) - res._install_hr_localizations() - return res - - def write(self, vals): - res = super().write(vals) - if 'country_id' in vals: - self._install_hr_localizations() - return res