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.

33 lines
1.2 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("Barcode Scanned", required=True)
  10. @api.multi
  11. def validate_sheet(self):
  12. sheet_id = self._context.get("active_id")
  13. sheet_model = self._context.get("active_model")
  14. sheet = self.env[sheet_model].browse(sheet_id)
  15. card = self.env["member.card"].search(
  16. [("barcode", "=", self.barcode)]
  17. )
  18. if not len(card):
  19. raise UserError("Please set a correct barcode.")
  20. user = card[0].partner_id
  21. if not user:
  22. raise UserError(
  23. "Only super-cooperators and administrators can validate attendance sheets."
  24. )
  25. sheet.validated_by = user
  26. sheet.validate()
  27. def on_barcode_scanned(self, barcode):
  28. self.barcode = barcode