mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[MIG] hr_payroll_attendance: for Odoo Enterprise 13.0
Move some concerns to other modules, refactor new API to make it possible to use timesheets and attendances together. Now possible to add attendances by hand or import via smart button and 'recompute' attendances.
This commit is contained in:
@@ -1,12 +1,31 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
from odoo import api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class HrAttendance(models.Model):
|
||||
_inherit = 'hr.attendance'
|
||||
|
||||
payslip_id = fields.Many2one('hr.payslip', string="Payslip", readonly=True, ondelete='set null')
|
||||
payslip_id = fields.Many2one('hr.payslip', string="Payslip", ondelete='set null')
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
if isinstance(vals_list, dict):
|
||||
vals_list = [vals_list]
|
||||
|
||||
payslips = self.env['hr.payslip'].sudo().browse([d.get('payslip_id', 0) for d in vals_list])
|
||||
if any(p.state not in ('draft', 'verify') for p in payslips.exists()):
|
||||
raise ValidationError('Cannot create attendance linked to payslip that is not draft.')
|
||||
return super().create(vals_list)
|
||||
|
||||
def write(self, values):
|
||||
payslip_id = values.get('payslip_id')
|
||||
if payslip_id:
|
||||
payslip = self.env['hr.payslip'].sudo().browse(payslip_id)
|
||||
if payslip.exists().state not in ('draft', 'verify'):
|
||||
raise ValidationError('Cannot modify attendance linked to payslip that is not draft.')
|
||||
return super().write(values)
|
||||
|
||||
def unlink(self):
|
||||
attn_with_payslip = self.filtered(lambda a: a.payslip_id)
|
||||
|
||||
Reference in New Issue
Block a user