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.

51 lines
1.7 KiB

  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields, api, exceptions, _
  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. barcode = fields.Char(string="Barcode", required=True)
  10. annotation = fields.Text(
  11. "Important information requiring permanent member assistance", default=""
  12. )
  13. feedback = fields.Text(
  14. "General feedback"
  15. )
  16. worker_nb_feedback = fields.Selection(
  17. [
  18. ("not_enough", "Not enough"),
  19. ("enough", "Enough"),
  20. ("too_many", "Too many"),
  21. ],
  22. string="Number of workers",
  23. required=True
  24. )
  25. @api.multi
  26. def validate_sheet(self):
  27. sheet_id = self._context.get("active_id")
  28. sheet_model = self._context.get("active_model")
  29. sheet = self.env[sheet_model].browse(sheet_id)
  30. card = self.env["member.card"].search(
  31. [("barcode", "=", self.barcode)]
  32. )
  33. if not len(card):
  34. raise UserError("Please set a correct barcode.")
  35. user = card[0].partner_id
  36. if not user:
  37. raise UserError(
  38. "Only super-cooperators and administrators can validate attendance sheets."
  39. )
  40. sheet.annotation = self.annotation
  41. sheet.feedback = self.feedback
  42. sheet.worker_nb_feedback = self.worker_nb_feedback
  43. sheet.validated_by = user
  44. sheet.validate()
  45. def on_barcode_scanned(self, barcode):
  46. self.barcode = barcode