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.8 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. 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. def on_barcode_scanned(self, barcode):
  25. self.barcode = barcode
  26. @api.multi
  27. def validate_sheet(self):
  28. sheet_id = self._context.get("active_id")
  29. sheet_model = self._context.get("active_model")
  30. sheet = self.env[sheet_model].browse(sheet_id)
  31. card = self.env["member.card"].search([("barcode", "=", self.barcode)])
  32. if not len(card):
  33. raise UserError(_("Please set a correct barcode."))
  34. user = card[0].partner_id
  35. if not user.super:
  36. raise UserError(
  37. _(
  38. "Only super-cooperators and administrators can validate attendance sheets."
  39. )
  40. )
  41. if self.annotation:
  42. sheet.annotation += self.annotation
  43. if sheet.feedback:
  44. sheet.feedback += self.feedback
  45. sheet.worker_nb_feedback = self.worker_nb_feedback
  46. sheet.validate(user or self.env.user.partner_id)