eiru_payslip_generator.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # -*- coding: utf-8 -*-
  2. from openerp import api, fields, models
  3. from openerp import workflow
  4. class EiruPayslipGenerator(models.Model):
  5. _inherit = 'hr.payslip'
  6. @api.model
  7. def generate_payroll_eiru(self, values):
  8. payslip = self.env['hr.payslip']
  9. payslip_run = self.env['hr.payslip.run'].search([('id', 'in', [values])])
  10. employee = self.env['hr.employee'].search([('active', '=', True)])
  11. payslip_ids = []
  12. slip_id = []
  13. for emp in employee:
  14. slip_data = self.onchange_employee_id(payslip_run.date_start, payslip_run.date_end, emp.id)
  15. if not self.env['hr.payslip'].search([('employee_id', '=', emp.id), ('date_from', '=', payslip_run.date_start), ('date_to', '=', payslip_run.date_end)]):
  16. res = {
  17. 'employee_id': emp.id,
  18. 'name': slip_data['value'].get('name', False),
  19. 'struct_id': slip_data['value'].get('struct_id', False),
  20. 'contract_id': slip_data['value'].get('contract_id', False),
  21. 'payslip_run_id': values,
  22. 'input_line_ids': [(0, 0, x) for x in slip_data['value'].get('input_line_ids', False)],
  23. 'worked_days_line_ids': [(0, 0, x) for x in slip_data['value'].get('worked_days_line_ids', False)],
  24. 'date_from': payslip_run.date_start,
  25. 'date_to': payslip_run.date_end,
  26. 'credit_note': payslip_run.credit_note,
  27. 'journal_id' : payslip_run.journal_id.id
  28. }
  29. # Crear Prayslip
  30. slip_id = payslip.create(res)
  31. payslip_ids.append(slip_id)
  32. # Workflow Loco
  33. slip_id.signal_workflow('hr_verify_sheet')
  34. slip_id.signal_workflow('process_sheet')
  35. if payslip_ids:
  36. payslip_run.write({'state': 'close'})
  37. return True if payslip_ids else False