hr_employee.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_hr_payslip_widget():
  4. user_store = r.env.user.store_id.id
  5. validate = '''
  6. SELECT EXISTS(
  7. SELECT table_name
  8. FROM information_schema.columns
  9. WHERE table_schema='public'
  10. AND table_name='hr_employee'
  11. AND column_name='store_id')
  12. '''
  13. query = '''
  14. SELECT
  15. payslip.id,
  16. payslip.number,
  17. payslip.create_date,
  18. employee.name_related,
  19. payslip_line.code,
  20. CASE
  21. WHEN payslip_line.code = 'NET'
  22. THEN payslip_line.total
  23. END AS NETO,
  24. CASE
  25. WHEN payslip_line.code = 'IPSC'
  26. THEN payslip_line.total
  27. END AS IPSC,
  28. CASE
  29. WHEN payslip_line.code = 'IPSE'
  30. THEN payslip_line.total
  31. END AS IPSE
  32. FROM hr_payslip AS payslip
  33. LEFT JOIN hr_employee AS employee
  34. ON employee.id = payslip.employee_id
  35. LEFT JOIN hr_payslip_line AS payslip_line
  36. ON payslip_line.slip_id = payslip.id
  37. WHERE TO_CHAR(payslip.date_to,'YYYY-MM') = TO_CHAR(current_date,'YYYY-MM')
  38. AND payslip.state in ('done','paid')
  39. AND payslip_line.code in ('NET','IPSC','IPSE')
  40. AND employee.store_id = ''' + str(user_store) + '''
  41. GROUP BY
  42. payslip.id,
  43. payslip.number,
  44. employee.name_related,
  45. payslip_line.code,
  46. payslip_line.total
  47. '''
  48. r.cr.execute(validate)
  49. for j in r.cr.fetchall():
  50. band = j[0]
  51. if band == True:
  52. r.cr.execute(query)
  53. return [
  54. {
  55. 'payslip_id': j[0],
  56. 'number': j[1],
  57. 'date': j[2],
  58. 'name': j[3],
  59. 'code': j[4],
  60. 'net': j[5],
  61. 'ipsc': j[6],
  62. 'ipse': j[7],
  63. } for j in r.cr.fetchall()
  64. ]