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.

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