You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.8 KiB

  1. # coding: utf-8
  2. def migrate(cr, version):
  3. """
  4. The Char field 'code' from shift stage is now a Selection Field
  5. named 'state'.
  6. """
  7. # Set new field state
  8. cr.execute(
  9. """
  10. UPDATE beesdoo_shift_shift
  11. SET state = old_code
  12. """
  13. )
  14. # Map new stage from corresponding old stage
  15. cr.execute(
  16. """
  17. UPDATE beesdoo_shift_shift
  18. SET state = 'absent_2'
  19. FROM res_partner
  20. WHERE beesdoo_shift_shift.worker_id = res_partner.id
  21. AND (
  22. beesdoo_shift_shift.old_code = 'absent'
  23. OR (
  24. beesdoo_shift_shift.old_code = 'excused'
  25. AND res_partner.working_mode = 'irregular'
  26. )
  27. )
  28. """
  29. )
  30. cr.execute(
  31. """
  32. UPDATE beesdoo_shift_shift
  33. SET state = 'absent_1'
  34. FROM res_partner
  35. WHERE beesdoo_shift_shift.worker_id = res_partner.id
  36. AND beesdoo_shift_shift.old_code = 'excused'
  37. AND res_partner.working_mode = 'regular'
  38. """
  39. )
  40. cr.execute(
  41. """
  42. UPDATE beesdoo_shift_shift
  43. SET state = 'absent_0'
  44. FROM res_partner
  45. WHERE beesdoo_shift_shift.worker_id = res_partner.id
  46. AND beesdoo_shift_shift.old_code = 'excused_necessity'
  47. """
  48. )
  49. cr.execute(
  50. """
  51. UPDATE beesdoo_shift_shift
  52. SET state = 'absent_0'
  53. WHERE beesdoo_shift_shift.state = 'excused'
  54. """
  55. )
  56. cr.execute(
  57. """
  58. DELETE FROM beesdoo_shift_shift
  59. WHERE beesdoo_shift_shift.state = 'absent'
  60. """
  61. )
  62. # Drop temporary columns
  63. cr.execute("ALTER TABLE beesdoo_shift_shift DROP COLUMN old_code")