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.

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