123456789101112131415161718192021222324252627282930313233343536373839404142 |
- # -*- coding: utf-8 -*-
- from openerp import api, fields, models
- from openerp import workflow
- class EiruPayslipGenerator(models.Model):
- _inherit = 'hr.payslip'
- @api.model
- def generate_payroll_eiru(self, values):
- payslip = self.env['hr.payslip']
- payslip_run = self.env['hr.payslip.run'].search([('id', 'in', [values])])
- employee = self.env['hr.employee'].search([('active', '=', True)])
- payslip_ids = []
- slip_id = []
- for emp in employee:
- slip_data = self.onchange_employee_id(payslip_run.date_start, payslip_run.date_end, emp.id)
- if not self.env['hr.payslip'].search([('employee_id', '=', emp.id), ('date_from', '=', payslip_run.date_start), ('date_to', '=', payslip_run.date_end)]):
- res = {
- 'employee_id': emp.id,
- 'name': slip_data['value'].get('name', False),
- 'struct_id': slip_data['value'].get('struct_id', False),
- 'contract_id': slip_data['value'].get('contract_id', False),
- 'payslip_run_id': values,
- 'input_line_ids': [(0, 0, x) for x in slip_data['value'].get('input_line_ids', False)],
- 'worked_days_line_ids': [(0, 0, x) for x in slip_data['value'].get('worked_days_line_ids', False)],
- 'date_from': payslip_run.date_start,
- 'date_to': payslip_run.date_end,
- 'credit_note': payslip_run.credit_note,
- 'journal_id' : payslip_run.journal_id.id
- }
- # Crear Prayslip
- slip_id = payslip.create(res)
- payslip_ids.append(slip_id)
- # Workflow Loco
- slip_id.signal_workflow('hr_verify_sheet')
- slip_id.signal_workflow('process_sheet')
- if payslip_ids:
- payslip_run.write({'state': 'close'})
- return True if payslip_ids else False
|