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.

80 lines
2.9 KiB

  1. # -*- coding: utf-8 -*-
  2. from openerp import _, api, exceptions, fields, models
  3. from openerp.exceptions import UserError, ValidationError
  4. class ValidateAttendanceSheet(models.TransientModel):
  5. _name = "beesdoo.shift.sheet.validate"
  6. _description = """Check the user name and validate sheet.
  7. Useless for users in group_cooperative_admin"""
  8. _inherit = ["barcodes.barcode_events_mixin"]
  9. @api.multi
  10. def _default_annotation(self):
  11. """
  12. The annotation is pre-filled with a warning message
  13. if a regular worker is added and should have been expected.
  14. """
  15. sheet_id = self._context.get("active_id")
  16. sheet_model = self._context.get("active_model")
  17. sheet = self.env[sheet_model].browse(sheet_id)
  18. warning_message = ""
  19. for added_shift in sheet.added_shift_ids:
  20. is_regular_worker = added_shift.worker_id.working_mode == "regular"
  21. is_compensation = added_shift.is_compensation
  22. if is_regular_worker and not is_compensation:
  23. warning_message += (
  24. _(
  25. "Warning : %s attended its shift as a normal one but was not expected. "
  26. "Something may be wrong in his/her personnal informations.\n\n"
  27. )
  28. % added_shift.worker_id.name
  29. )
  30. return warning_message
  31. barcode = fields.Char(string="Barcode", required=True)
  32. annotation = fields.Text(
  33. "Important information requiring permanent member assistance",
  34. default=_default_annotation,
  35. )
  36. feedback = fields.Text("General feedback")
  37. worker_nb_feedback = fields.Selection(
  38. [
  39. ("not_enough", "Not enough"),
  40. ("enough", "Enough"),
  41. ("too_many", "Too many"),
  42. ],
  43. string="Number of workers",
  44. required=True,
  45. )
  46. def on_barcode_scanned(self, barcode):
  47. self.barcode = barcode
  48. @api.multi
  49. def validate_sheet(self):
  50. sheet_id = self._context.get("active_id")
  51. sheet_model = self._context.get("active_model")
  52. sheet = self.env[sheet_model].browse(sheet_id)
  53. card = self.env["member.card"].search([("barcode", "=", self.barcode)])
  54. if not len(card):
  55. raise UserError(_("Please set a correct barcode."))
  56. partner = card[0].partner_id
  57. is_admin = partner.user_ids.has_group(
  58. "beesdoo_shift.group_cooperative_admin"
  59. )
  60. if not partner.super and not is_admin:
  61. raise UserError(
  62. _(
  63. "Only super-cooperators and administrators can validate attendance sheets."
  64. )
  65. )
  66. if self.annotation:
  67. sheet.annotation += self.annotation
  68. if sheet.feedback:
  69. sheet.feedback += self.feedback
  70. sheet.worker_nb_feedback = self.worker_nb_feedback
  71. sheet._validate(partner or self.env.user.partner_id)