Browse Source

[ADD] b_shift : optional validation by card scan

pull/125/head
Elouan Le Bars 5 years ago
parent
commit
e9f55e834a
  1. 4
      beesdoo_shift/data/system_parameter.xml
  2. 23
      beesdoo_shift/models/res_config.py
  3. 1
      beesdoo_shift/views/res_config_view.xml
  4. 29
      beesdoo_shift/wizard/validate_attendance_sheet.py
  5. 11
      beesdoo_shift/wizard/validate_attendance_sheet.xml

4
beesdoo_shift/data/system_parameter.xml

@ -31,6 +31,10 @@
<field name="key">regular_counter_to_unsubscribe</field> <field name="key">regular_counter_to_unsubscribe</field>
<field name="value">-4</field> <field name="value">-4</field>
</record> </record>
<record id="beesdoo_shift.card_support" model="ir.config_parameter">
<field name="key">beesdoo_shift.card_support</field>
<field name="value">False</field>
</record>
<record id="beesdoo_shift.attendance_sheet_generation_interval" model="ir.config_parameter"> <record id="beesdoo_shift.attendance_sheet_generation_interval" model="ir.config_parameter">
<field name="key">beesdoo_shift.attendance_sheet_generation_interval</field> <field name="key">beesdoo_shift.attendance_sheet_generation_interval</field>
<field name="value">15</field> <field name="value">15</field>

23
beesdoo_shift/models/res_config.py

@ -10,21 +10,29 @@ class ShiftConfigSettings(models.TransientModel):
_name = "beesdoo.shift.config.settings" _name = "beesdoo.shift.config.settings"
_inherit = "res.config.settings" _inherit = "res.config.settings"
card_support = fields.Boolean(
string="Scan cooperators cards instead of login for sheets validation",
default=False
)
default_task_type_id = fields.Many2one( default_task_type_id = fields.Many2one(
"beesdoo.shift.type", "beesdoo.shift.type",
string="Default Task Type", string="Default Task Type",
help="Default task type for attendance sheet pre-filling.",
help="Default task type for attendance sheet pre-filling",
required=True,
) )
attendance_sheet_generation_interval = fields.Integer( attendance_sheet_generation_interval = fields.Integer(
string="Time interval for attendance sheet generation", string="Time interval for attendance sheet generation",
help="Time interval expressed in minutes", help="Time interval expressed in minutes",
required=True,
) )
@api.multi @api.multi
def set_params(self): def set_params(self):
self.ensure_one() self.ensure_one()
parameters = self.env["ir.config_parameter"] parameters = self.env["ir.config_parameter"]
parameters.set_param(
"beesdoo_shift.card_support", str(self.card_support),
)
parameters.set_param( parameters.set_param(
"beesdoo_shift.default_task_type_id", "beesdoo_shift.default_task_type_id",
str(self.default_task_type_id.id), str(self.default_task_type_id.id),
@ -34,6 +42,17 @@ class ShiftConfigSettings(models.TransientModel):
str(self.attendance_sheet_generation_interval), str(self.attendance_sheet_generation_interval),
) )
@api.multi
def get_default_card_support(self):
return {
"card_support": (
self.env["ir.config_parameter"].get_param(
"beesdoo_shift.card_support"
)
== "True"
)
}
@api.multi @api.multi
def get_default_task_type_id(self): def get_default_task_type_id(self):
return { return {

1
beesdoo_shift/views/res_config_view.xml

@ -40,6 +40,7 @@
</header> </header>
<separator string="General Settings"/> <separator string="General Settings"/>
<group name="Attendance Sheets"> <group name="Attendance Sheets">
<field name="card_support"/>
<field name="attendance_sheet_generation_interval"/> <field name="attendance_sheet_generation_interval"/>
<field name="default_task_type_id"/> <field name="default_task_type_id"/>
</group> </group>

29
beesdoo_shift/wizard/validate_attendance_sheet.py

@ -9,6 +9,11 @@ class ValidateAttendanceSheet(models.TransientModel):
Useless for users in group_cooperative_admin""" Useless for users in group_cooperative_admin"""
_inherit = ["barcodes.barcode_events_mixin"] _inherit = ["barcodes.barcode_events_mixin"]
def _get_card_support_setting(self):
return self.env["ir.config_parameter"].get_param(
"beesdoo_shift.card_support"
) == "True"
@api.multi @api.multi
def _default_annotation(self): def _default_annotation(self):
""" """
@ -35,7 +40,10 @@ class ValidateAttendanceSheet(models.TransientModel):
) )
return warning_message return warning_message
barcode = fields.Char(string="Barcode", required=True)
card_support = fields.Boolean(default=_get_card_support_setting)
user_id = fields.Many2one("res.users", string="Login")
password = fields.Char(string="Password")
barcode = fields.Char(string="Barcode")
annotation = fields.Text( annotation = fields.Text(
"Important information requiring permanent member assistance", "Important information requiring permanent member assistance",
default=_default_annotation, default=_default_annotation,
@ -59,13 +67,24 @@ class ValidateAttendanceSheet(models.TransientModel):
sheet_id = self._context.get("active_id") sheet_id = self._context.get("active_id")
sheet_model = self._context.get("active_model") sheet_model = self._context.get("active_model")
sheet = self.env[sheet_model].browse(sheet_id) sheet = self.env[sheet_model].browse(sheet_id)
card = self.env["member.card"].search([("barcode", "=", self.barcode)])
if not len(card):
raise UserError(_("Please set a correct barcode."))
partner = card[0].partner_id
if self.card_support:
# Login with barcode
card = self.env["member.card"].search([("barcode", "=", self.barcode)])
if not len(card):
raise UserError(_("Please set a correct barcode."))
partner = card[0].partner_id
else:
# Login with credentials
if not self.user_id:
raise UserError(_("Please enter an user name."))
self.user_id.sudo(self.user_id.id).check_credentials(self.password)
partner = self.user_id.partner_id
is_admin = partner.user_ids.has_group( is_admin = partner.user_ids.has_group(
"beesdoo_shift.group_cooperative_admin" "beesdoo_shift.group_cooperative_admin"
) )
if not partner.super and not is_admin: if not partner.super and not is_admin:
raise UserError( raise UserError(
_( _(

11
beesdoo_shift/wizard/validate_attendance_sheet.xml

@ -17,7 +17,16 @@
<group> <group>
<field name="worker_nb_feedback" /> <field name="worker_nb_feedback" />
</group> </group>
<group string="Scan your card">
<field name="card_support" invisible="1" />
<group string="Login"
attrs="{'invisible': [('card_support', '=', True)]}"
>
<field name="user_id" />
<field name="password" password="True"/>
</group>
<group string="Scan your card"
attrs="{'invisible': [('card_support', '=', False)]}"
>
<field name="barcode" /> <field name="barcode" />
</group> </group>
</sheet> </sheet>

Loading…
Cancel
Save