rrhh.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields, api
  3. from datetime import datetime
  4. from pytz import timezone
  5. DATE_FORMAT = '%Y-%m'
  6. class HrEmployee(models.Model):
  7. _inherit = 'hr.employee'
  8. def get_timezone(self):
  9. tz_name = self._context.get('tz') or self.env.user.tz
  10. return timezone(tz_name)
  11. def get_server_datetime(self):
  12. return datetime.now(self.get_timezone()).strftime(DATE_FORMAT)
  13. @api.model
  14. def getHHRRWidget(self,domain):
  15. user_store = self.env.user.store_id.id
  16. domain.append(('store_id','=',user_store))
  17. HrEmployee = self.env['hr.employee'].search(domain)
  18. date_server = self.get_server_datetime()
  19. values = []
  20. employee_ids = []
  21. for employee in HrEmployee:
  22. total = 0
  23. ipse = 0
  24. amortized = 0
  25. faltas = 0
  26. residual = 0
  27. HrPayslip = self.env['hr.payslip'].search([('employee_id','=',employee.id),('state','in',['done','paid']),('date_to','like',date_server)])
  28. for payslip in HrPayslip:
  29. HrPayslipLine = self.env['hr.payslip.line'].search([('slip_id','=',payslip.id),])
  30. for line in HrPayslipLine:
  31. if(line.code in ['BASIC','CMS']):
  32. total += line.total
  33. if(line.code in ['IPSE']):
  34. ipse += (line.total*-1)
  35. if(line.code in ['ADPER']):
  36. amortized += (line.total*-1)
  37. if(line.code in ['FALTAS']):
  38. faltas += (line.total*-1)
  39. if(line.code in ['NET']):
  40. residual += line.total
  41. values.append({
  42. 'id': employee.id,
  43. 'name': employee.name,
  44. 'identification_id': employee.identification_id,
  45. 'payslip': total - ipse - faltas,
  46. 'amortized': amortized,
  47. 'residual': residual,
  48. })
  49. return values
  50. def get_account_account_ipsc (self, code):
  51. return self.env['account.account'].search([('code', '=', code)])
  52. @api.model
  53. def getPayslipTotalWidget(self,domain):
  54. HrPayslip = self.env['hr.payslip'].search(domain)
  55. values = []
  56. total = 0
  57. ipse = 0
  58. ipsc = 0
  59. faltas = 0
  60. amortized = 0
  61. residual = 0
  62. for payslip in HrPayslip:
  63. HrPayslipLine = self.env['hr.payslip.line'].search([('slip_id','=',payslip.id)])
  64. accountIpsC = self.get_account_account_ipsc('245000')
  65. accountId= accountIpsC.id
  66. for line in HrPayslipLine:
  67. if(line.code in ['BASIC','CMS']):
  68. total += line.total
  69. if(line.code in ['FALTAS']):
  70. faltas += (line.total*-1)
  71. if(line.code in ['IPSE']):
  72. AccountMoveLine = self.env['account.move.line'].search([('move_id','=',payslip.move_id.id),('partner_id', '=', payslip.employee_id.address_home_id.id),('reconcile_id','=',False),('credit','>',0)])
  73. if(len(AccountMoveLine) > 0):
  74. ipse += (line.total*-1)
  75. if(line.code in ['IPSC']):
  76. AccountMoveLine = self.env['account.move.line'].search([('move_id','=',payslip.move_id.id),('ref', '=', payslip.number),('reconcile_id', '=',False),('account_id', '=', accountId)])
  77. if(len(AccountMoveLine) > 0):
  78. ipsc += line.total
  79. if(payslip.state == 'done'):
  80. if(line.code in ['NET']):
  81. residual += line.total
  82. amortized = total - ipse - faltas - residual
  83. values.append({
  84. 'payslip': total - ipse - faltas,
  85. 'amortized': amortized,
  86. 'residual': residual,
  87. 'ipse': ipse,
  88. 'ipsc': ipsc,
  89. })
  90. return values