Browse Source

[UPD] b_shift : security groups

Add a new groupe only for attendance
sheets validation.
pull/143/head
Elouan Le Bars 5 years ago
parent
commit
c162e9bb48
  1. 8
      beesdoo_shift/models/attendance_sheet.py
  2. 28
      beesdoo_shift/security/group.xml
  3. 6
      beesdoo_shift/security/ir.model.access.csv
  4. 18
      beesdoo_shift/tests/test_beesdoo_shift.py
  5. 16
      beesdoo_shift/views/attendance_sheet.xml
  6. 8
      beesdoo_shift/wizard/validate_attendance_sheet.py

8
beesdoo_shift/models/attendance_sheet.py

@ -306,6 +306,12 @@ class AttendanceSheet(models.Model):
) )
def on_barcode_scanned(self, barcode): def on_barcode_scanned(self, barcode):
if self.env.user.has_group("beesdoo_shift.group_shift_attendance"):
raise UserError(
_("You must be logged as 'Attendance Sheet Generic Access' "
" if you want to scan cards.")
)
if self.state == "validated": if self.state == "validated":
raise UserError( raise UserError(
_("A validated attendance sheet can't be modified") _("A validated attendance sheet can't be modified")
@ -564,7 +570,7 @@ class AttendanceSheet(models.Model):
) )
# Open a validation wizard only if not admin # Open a validation wizard only if not admin
if self.env.user.has_group("beesdoo_shift.group_cooperative_admin"):
if self.env.user.has_group("beesdoo_shift.group_shift_attendance_sheet_validation"):
if not self.worker_nb_feedback: if not self.worker_nb_feedback:
raise UserError( raise UserError(
_("Please give your feedback about the number of workers.") _("Please give your feedback about the number of workers.")

28
beesdoo_shift/security/group.xml

@ -4,17 +4,20 @@
<field name="category_id" <field name="category_id"
ref="base.module_category_cooperative_management"/> ref="base.module_category_cooperative_management"/>
</record> </record>
<record id="group_shift_attendance_sheet_validation" model="res.groups">
<field name="name">Attendance Sheet Validation</field>
<field name="category_id" ref="base.module_category_cooperative_management"/>
<field name="implied_ids" eval="[(4, ref('group_shift_attendance_sheet'))]"/>
</record>
<record id="group_shift_attendance" model="res.groups"> <record id="group_shift_attendance" model="res.groups">
<field name="name">Shift and Worker Access</field>
<field name="category_id"
ref="base.module_category_cooperative_management"/>
<field name="name">Shift and Worker Read Access</field>
<field name="category_id" ref="base.module_category_cooperative_management"/>
<field name="implied_ids" eval="[(4, ref('group_shift_attendance_sheet'))]"/>
</record> </record>
<record id="group_shift_management" model="res.groups"> <record id="group_shift_management" model="res.groups">
<field name="name">Shift Management</field>
<field name="category_id"
ref="base.module_category_cooperative_management"/>
<field name="implied_ids"
eval="[(4, ref('group_shift_attendance'))]"/>
<field name="name">Shifts and Attendance Sheets Management</field>
<field name="category_id" ref="base.module_category_cooperative_management"/>
<field name="implied_ids" eval="[(4, ref('group_shift_attendance'))]"/>
</record> </record>
<record id="group_planning_management" model="res.groups"> <record id="group_planning_management" model="res.groups">
<field name="name">Planning Management</field> <field name="name">Planning Management</field>
@ -25,10 +28,11 @@
</record> </record>
<record id="group_cooperative_admin" model="res.groups"> <record id="group_cooperative_admin" model="res.groups">
<field name="name">Cooperative Admin</field> <field name="name">Cooperative Admin</field>
<field name="category_id"
ref="base.module_category_cooperative_management"/>
<field name="implied_ids"
eval="[(4, ref('group_planning_management')), (4, ref('group_shift_attendance_sheet'))]" />
<field name="category_id" ref="base.module_category_cooperative_management"/>
<field name="implied_ids" eval="[(6, 0, [ref('group_planning_management'),
ref('group_shift_attendance_sheet_validation'),
ref('group_shift_attendance_sheet'),])]"
/>
<field name="users" <field name="users"
eval="[(4, ref('base.user_root')), eval="[(4, ref('base.user_root')),
(4, ref('base.user_admin'))]"/> (4, ref('base.user_admin'))]"/>

6
beesdoo_shift/security/ir.model.access.csv

@ -12,13 +12,13 @@ access_beesdoo_shift_daynumber,access_beesdoo_shift_daynumber,model_beesdoo_shif
read_beesdoo_shift_planning,read_beesdoo_shift_planning,model_beesdoo_shift_planning,,1,0,0,0 read_beesdoo_shift_planning,read_beesdoo_shift_planning,model_beesdoo_shift_planning,,1,0,0,0
access_beesdoo_shift_template,access_beesdoo_shift_template,model_beesdoo_shift_template,group_shift_attendance,1,0,0,0 access_beesdoo_shift_template,access_beesdoo_shift_template,model_beesdoo_shift_template,group_shift_attendance,1,0,0,0
write_beesdoo_shift_shift,write_beesdoo_shift_shift,model_beesdoo_shift_shift,group_shift_attendance,1,1,0,0 write_beesdoo_shift_shift,write_beesdoo_shift_shift,model_beesdoo_shift_shift,group_shift_attendance,1,1,0,0
manage_beesdoo_shift_shift,manage_beesdoo_shift_shift,model_beesdoo_shift_shift,group_shift_management,1,1,1,1
manage_beesdoo_shift_shift,manage_beesdoo_shift_shift,model_beesdoo_shift_shift,group_shift_attendance,1,1,1,1
manage_beesdoo_shift_type,manage_beesdoo_shift_type,model_beesdoo_shift_type,group_planning_management,1,1,1,1 manage_beesdoo_shift_type,manage_beesdoo_shift_type,model_beesdoo_shift_type,group_planning_management,1,1,1,1
manage_beesdoo_shift_daynumber,manage_beesdoo_shift_daynumber,model_beesdoo_shift_daynumber,group_planning_management,1,1,1,1 manage_beesdoo_shift_daynumber,manage_beesdoo_shift_daynumber,model_beesdoo_shift_daynumber,group_planning_management,1,1,1,1
manage_beesdoo_shift_planning,manage_beesdoo_shift_planning,model_beesdoo_shift_planning,group_planning_management,1,1,1,1 manage_beesdoo_shift_planning,manage_beesdoo_shift_planning,model_beesdoo_shift_planning,group_planning_management,1,1,1,1
manage_beesdoo_shift_template,manage_beesdoo_shift_template,model_beesdoo_shift_template,group_planning_management,1,1,1,1 manage_beesdoo_shift_template,manage_beesdoo_shift_template,model_beesdoo_shift_template,group_planning_management,1,1,1,1
manage_beesdoo_shift_sheet_shift,beesdoo_shift_sheet_shift,model_beesdoo_shift_sheet_shift,group_cooperative_admin,1,1,1,1
manage_beesdoo_shift_sheet_expected,manage_beesdoo_shift_sheet_expected,model_beesdoo_shift_sheet_expected,group_cooperative_admin,1,1,1,1
manage_beesdoo_shift_sheet_shift,beesdoo_shift_sheet_shift,model_beesdoo_shift_sheet_shift,group_shift_attendance,1,1,1,1
manage_beesdoo_shift_sheet_expected,manage_beesdoo_shift_sheet_expected,model_beesdoo_shift_sheet_expected,group_shift_attendance,1,1,1,1
manage_cooperative_status,manage_cooperative_status,model_cooperative_status,group_cooperative_admin,1,1,1,1 manage_cooperative_status,manage_cooperative_status,model_cooperative_status,group_cooperative_admin,1,1,1,1
manage_cooperative_exempt_reason,manage_cooperative_exempt_reason,model_cooperative_exempt_reason,group_cooperative_admin,1,1,1,1 manage_cooperative_exempt_reason,manage_cooperative_exempt_reason,model_cooperative_exempt_reason,group_cooperative_admin,1,1,1,1
read_beesdoo_shift_journal,read_beesdoo_shift_journal,model_beesdoo_shift_journal,group_cooperative_admin,1,0,1,1 read_beesdoo_shift_journal,read_beesdoo_shift_journal,model_beesdoo_shift_journal,group_cooperative_admin,1,0,1,1

18
beesdoo_shift/tests/test_beesdoo_shift.py

@ -257,6 +257,7 @@ class TestBeesdooShift(TransactionCase):
self.user_generic self.user_generic
)._generate_attendance_sheet() )._generate_attendance_sheet()
sheet_1 = self.search_sheets(self.start_in_1, self.end_in_1,) sheet_1 = self.search_sheets(self.start_in_1, self.end_in_1,)
sheet_1 = sheet_1.sudo(self.user_generic)
""" """
Expected workers are : Expected workers are :
@ -354,14 +355,6 @@ class TestBeesdooShift(TransactionCase):
} }
) )
# Wait necessary time for shifts to begin
waiting_time = (self.start_in_1 - datetime.now()).total_seconds()
if waiting_time > 0:
with self.assertRaises(UserError) as e:
sheet_1.validate_with_checks()
self.assertIn("wait", str(e.exception))
time.sleep(waiting_time)
# TODO: test validation with wizard (as generic user) # TODO: test validation with wizard (as generic user)
# class odoo.tests.common.Form(recordp, view=None) # class odoo.tests.common.Form(recordp, view=None)
# is only available from version 12 # is only available from version 12
@ -370,6 +363,15 @@ class TestBeesdooShift(TransactionCase):
# Validation without wizard (as admin user) # Validation without wizard (as admin user)
sheet_1 = sheet_1.sudo(self.user_admin) sheet_1 = sheet_1.sudo(self.user_admin)
# Wait necessary time for shifts to begin
waiting_time = (self.start_in_1 - datetime.now()).total_seconds()
if waiting_time > 0:
with self.assertRaises(UserError) as e:
sheet_1.validate_with_checks()
self.assertIn("wait", str(e.exception))
time.sleep(waiting_time)
sheet_1.worker_nb_feedback = "enough" sheet_1.worker_nb_feedback = "enough"
sheet_1.feedback = "Great session." sheet_1.feedback = "Great session."
sheet_1.notes = "Important information." sheet_1.notes = "Important information."

16
beesdoo_shift/views/attendance_sheet.xml

@ -147,11 +147,11 @@
<button name="button_mark_as_read" type="object" <button name="button_mark_as_read" type="object"
class="oe_stat_button" icon="fa-check" class="oe_stat_button" icon="fa-check"
string="Mark as read" string="Mark as read"
groups="beesdoo_shift.group_cooperative_admin"
groups="beesdoo_shift.group_shift_attendance"
/> />
<button name="toggle_active" <button name="toggle_active"
type="object" type="object"
groups="beesdoo_shift.group_cooperative_admin"
groups="beesdoo_shift.group_shift_attendance"
class="oe_stat_button" class="oe_stat_button"
icon="fa-archive"> icon="fa-archive">
<field name="active" widget="boolean_button" options='{"terminology": "archive"}'/> <field name="active" widget="boolean_button" options='{"terminology": "archive"}'/>
@ -172,8 +172,8 @@
<separator string="Expected workers" /> <separator string="Expected workers" />
<field name="expected_shift_ids" /> <field name="expected_shift_ids" />
<br/> <br/>
<group string="Feedback"
groups="beesdoo_shift.group_cooperative_admin">
<group col="1" string="Feedback"
groups="beesdoo_shift.group_shift_attendance">
<field name="notes" /> <field name="notes" />
<field name="feedback" /> <field name="feedback" />
<field name="worker_nb_feedback" /> <field name="worker_nb_feedback" />
@ -183,7 +183,7 @@
<div class="oe_chatter"> <div class="oe_chatter">
<field name="message_ids" <field name="message_ids"
widget="mail_thread" widget="mail_thread"
groups="beesdoo_shift.group_cooperative_admin"
groups="beesdoo_shift.group_shift_attendance"
/> />
</div> </div>
</form> </form>
@ -238,18 +238,18 @@
name="Non-validated sheets" name="Non-validated sheets"
parent="menu_sheet_top" parent="menu_sheet_top"
action="action_sheet_admin_non_validated" action="action_sheet_admin_non_validated"
groups="beesdoo_shift.group_cooperative_admin"
groups="beesdoo_shift.group_shift_attendance"
/> />
<menuitem id="menu_sheet_admin_annotated" <menuitem id="menu_sheet_admin_annotated"
name="Unread notes" name="Unread notes"
parent="menu_sheet_top" parent="menu_sheet_top"
action="action_sheet_admin_annotated" action="action_sheet_admin_annotated"
groups="beesdoo_shift.group_cooperative_admin"
groups="beesdoo_shift.group_shift_attendance"
/> />
<menuitem id="menu_sheet_admin_list" <menuitem id="menu_sheet_admin_list"
name="All sheets" name="All sheets"
parent="menu_sheet_top" parent="menu_sheet_top"
action="action_sheet_admin_list" action="action_sheet_admin_list"
groups="beesdoo_shift.group_cooperative_admin"
groups="beesdoo_shift.group_shift_attendance"
/> />
</odoo> </odoo>

8
beesdoo_shift/wizard/validate_attendance_sheet.py

@ -8,7 +8,7 @@ from odoo.exceptions import UserError, ValidationError
class ValidateAttendanceSheet(models.TransientModel): class ValidateAttendanceSheet(models.TransientModel):
_name = "beesdoo.shift.sheet.validate" _name = "beesdoo.shift.sheet.validate"
_description = """Check the user name and validate sheet. _description = """Check the user name and validate sheet.
Useless for users in group_cooperative_admin"""
Useless for users in group_shift_attendance"""
_inherit = ["barcodes.barcode_events_mixin"] _inherit = ["barcodes.barcode_events_mixin"]
@api.multi @api.multi
@ -100,11 +100,11 @@ class ValidateAttendanceSheet(models.TransientModel):
user.sudo(user.id)._check_credentials(self.password) user.sudo(user.id)._check_credentials(self.password)
partner = user.partner_id partner = user.partner_id
is_admin = partner.user_ids.has_group(
"beesdoo_shift.group_cooperative_admin"
can_validate = partner.user_ids.has_group(
"beesdoo_shift.group_shift_attendance_sheet_validation"
) )
if not partner.super and not is_admin:
if not partner.super and not can_validate:
raise UserError( raise UserError(
_( _(
"Only super-cooperators and administrators can validate attendance sheets." "Only super-cooperators and administrators can validate attendance sheets."

Loading…
Cancel
Save