60 lines
2.8 KiB
Python
60 lines
2.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class ResConfigSettings(models.TransientModel):
|
|
_inherit = 'res.config.settings'
|
|
|
|
module_l10n_fr_hr_payroll = fields.Boolean(string='French Payroll')
|
|
module_l10n_be_hr_payroll = fields.Boolean(string='Belgium Payroll')
|
|
module_l10n_in_hr_payroll = fields.Boolean(string='Indian Payroll')
|
|
module_hr_payroll_account_iso20022 = fields.Boolean(string='Payroll with SEPA payment')
|
|
ytd_reset_day = fields.Integer(related="company_id.ytd_reset_day", readonly=False)
|
|
ytd_reset_month = fields.Selection(related="company_id.ytd_reset_month", readonly=False)
|
|
payslip_generate_and_send_trigger = fields.Selection(
|
|
[
|
|
('on_confirmed', 'When Confirmed'),
|
|
('on_paid', 'When Paid'),
|
|
('never', 'Manually'),
|
|
],
|
|
string='Payslips Generate and Send Trigger',
|
|
compute='_compute_payslip_generate_and_send_trigger',
|
|
inverse='_inverse_payslip_generate_and_send_trigger',
|
|
)
|
|
|
|
def _compute_payslip_generate_and_send_trigger(self):
|
|
""" Read the send trigger from ir.config_parameter, default to on_confirmed. """
|
|
# ir.config_parameter is global, so all settings records see the same value.
|
|
value = self.env['ir.config_parameter'].sudo().get_param(
|
|
'hr_payroll.payslip_generate_and_send_trigger', default='on_confirmed'
|
|
)
|
|
for record in self:
|
|
record.payslip_generate_and_send_trigger = value
|
|
|
|
def _inverse_payslip_generate_and_send_trigger(self):
|
|
""" Persist the send trigger to ir.config_parameter. """
|
|
self.env['ir.config_parameter'].sudo().set_param(
|
|
'hr_payroll.payslip_generate_and_send_trigger',
|
|
self.payslip_generate_and_send_trigger or 'on_confirmed',
|
|
)
|
|
|
|
@api.model_create_multi
|
|
def create(self, vals_list):
|
|
# Amazing workaround: non-stored related fields on company are a BAD idea since the 2 fields
|
|
# must follow the constraint '_check_ytd_reset_day'. The thing is, in case of related
|
|
# fields, the inverse write is done one value at a time, and thus the constraint is verified
|
|
# one value at a time... so it is likely to fail.
|
|
for vals in vals_list:
|
|
ytd_reset_day = vals.pop('ytd_reset_day', False) or self.env.company.ytd_reset_day
|
|
ytd_reset_month = vals.pop('ytd_reset_month', False) or self.env.company.ytd_reset_month
|
|
vals = {}
|
|
if ytd_reset_day != self.env.company.ytd_reset_day:
|
|
vals['ytd_reset_day'] = ytd_reset_day
|
|
if ytd_reset_month != self.env.company.ytd_reset_month:
|
|
vals['ytd_reset_month'] = ytd_reset_month
|
|
if vals:
|
|
self.env.company.write(vals)
|
|
return super().create(vals_list)
|