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.

54 lines
1.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. 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. partner = card[0].partner_id
  35. is_admin = partner.user_ids.has_group(
  36. "beesdoo_shift.group_cooperative_admin"
  37. )
  38. if not partner.super and not is_admin:
  39. raise UserError(
  40. _(
  41. "Only super-cooperators and administrators can validate attendance sheets."
  42. )
  43. )
  44. if self.annotation:
  45. sheet.annotation += self.annotation
  46. if sheet.feedback:
  47. sheet.feedback += self.feedback
  48. sheet.worker_nb_feedback = self.worker_nb_feedback
  49. sheet.validate(partner or self.env.user.partner_id)