Browse Source

[ADD] b_shift : barcode scan to attendance sheet validation

pull/143/head
Elouan Le Bars 5 years ago
parent
commit
8b8417305f
  1. 34
      beesdoo_shift/wizard/validate_attendance_sheet.py
  2. 5
      beesdoo_shift/wizard/validate_attendance_sheet.xml

34
beesdoo_shift/wizard/validate_attendance_sheet.py

@ -7,33 +7,25 @@ class ValidateAttendanceSheet(models.TransientModel):
_name = "beesdoo.shift.sheet.validate"
_description = """Check the user name and validate sheet.
Useless for users in group_cooperative_admin"""
_inherit = ["barcodes.barcode_events_mixin"]
#card = fields.Many2one("member.card", string="MemberCard")
barcode = fields.Char(string="Barcode", required=True)
user = fields.Many2one("res.partner", compute="_compute_user", string="User Name", readonly=True)
@api.depends("barcode")
def _compute_user(self):
if self.barcode:
card = self.env["member.card"].search([("barcode", "=", self.barcode)])
if card:
self.user = card[0].partner_id
else:
self.user = False
# Is the "@api.multi" correct here ?
@api.multi
def validate_sheet(self):
if not self.user:
raise UserError("Please set a correct barcode.")
def validate_sheet(self, user):
sheet_id = self._context.get("active_id")
sheet_model = self._context.get("active_model")
sheet = self.env[sheet_model].browse(sheet_id)
if not self.user.super:
if not user.super:
raise UserError(
"You must be super-coop or admin to validate the sheet."
"Only super-cooperators and administrators can validate attendance sheets."
)
sheet.validated_by = self.user
# Following methods call not working
sheet.validated_by = user
sheet.validate()
return
def on_barcode_scanned(self, barcode):
card = self.env["member.card"].search(
[("barcode", "=", barcode)]
)
if not len(card):
raise UserError("Please set a correct barcode.")
self.validate_sheet(card[0].partner_id)

5
beesdoo_shift/wizard/validate_attendance_sheet.xml

@ -6,9 +6,10 @@
<form>
<label string="Beware : a validated sheet cannot be edited anymore and you won't be able to add any latecomers.
Emails will be sent to workers who did not attend their shift." />
<field name="_barcode_scanned" widget="barcode_handler"/>
<group>
<field name="user" />
<field name="barcode" />
<!--<field name="user" />-->
</group>
<footer>
<button type="object" name="validate_sheet"

Loading…
Cancel
Save