Browse Source

[REF] b_shift : code cleaning

pull/125/head
Elouan Le Bars 5 years ago
parent
commit
5ad726b2e7
  1. 44
      beesdoo_shift/models/attendance_sheet.py
  2. 7
      beesdoo_shift/models/res_config.py
  3. 5
      beesdoo_shift/security/group.xml
  4. 19
      beesdoo_shift/wizard/validate_attendance_sheet.py

44
beesdoo_shift/models/attendance_sheet.py

@ -18,10 +18,7 @@ class AttendanceSheetShift(models.AbstractModel):
@api.model @api.model
def default_task_type_id(self): def default_task_type_id(self):
parameters = self.env["ir.config_parameter"] parameters = self.env["ir.config_parameter"]
id = (
int(parameters.get_param("beesdoo_shift.default_task_type_id"))
or 1
)
id = int(parameters.get_param("beesdoo_shift.default_task_type_id", default=1))
task_types = self.env["beesdoo.shift.type"] task_types = self.env["beesdoo.shift.type"]
return task_types.browse(id) return task_types.browse(id)
@ -293,12 +290,13 @@ class AttendanceSheet(models.Model):
@api.constrains("expected_shift_ids", "added_shift_ids") @api.constrains("expected_shift_ids", "added_shift_ids")
def _constrain_unique_worker(self): def _constrain_unique_worker(self):
# Warning : map return generator in python3 (for Odoo 12) # Warning : map return generator in python3 (for Odoo 12)
added_ids = map(lambda s: s.worker_id.id, self.added_shift_ids)
expected_ids = map(lambda s: s.worker_id.id, self.expected_shift_ids)
replacement_ids = map(
lambda s: s.replacement_worker_id.id, self.expected_shift_ids
)
replacement_ids = filter(bool, replacement_ids)
added_ids = [s.worker_id.id for s in self.added_shift_ids]
expected_ids = [s.worker_id.id for s in self.expected_shift_ids]
replacement_ids = [
s.replacement_worker_id.id
for s in self.expected_shift_ids
if s.replacement_worker_id.id
]
ids = added_ids + expected_ids + replacement_ids ids = added_ids + expected_ids + replacement_ids
if (len(ids) - len(set(ids))) > 0: if (len(ids) - len(set(ids))) > 0:
@ -363,7 +361,7 @@ class AttendanceSheet(models.Model):
worker.working_mode, worker.working_mode,
) )
# expected shifts status update
# Expected shifts status update
for id in self.expected_shift_ids.ids: for id in self.expected_shift_ids.ids:
shift = self.env["beesdoo.shift.sheet.expected"].browse(id) shift = self.env["beesdoo.shift.sheet.expected"].browse(id)
if ( if (
@ -380,19 +378,17 @@ class AttendanceSheet(models.Model):
added_ids = map(lambda s: s.worker_id.id, self.added_shift_ids) added_ids = map(lambda s: s.worker_id.id, self.added_shift_ids)
if worker.id in added_ids:
return
# added shift creation
self.added_shift_ids |= self.added_shift_ids.new(
{
"task_type_id": self.added_shift_ids.default_task_type_id(),
"state": "done",
"attendance_sheet_id": self._origin.id,
"worker_id": worker.id,
"is_compensation": is_compensation,
}
)
if worker.id not in added_ids:
# Added shift creation
self.added_shift_ids |= self.added_shift_ids.new(
{
"task_type_id": self.added_shift_ids.default_task_type_id(),
"state": "done",
"attendance_sheet_id": self._origin.id,
"worker_id": worker.id,
"is_compensation": is_compensation,
}
)
@api.model @api.model
def create(self, vals): def create(self, vals):

7
beesdoo_shift/models/res_config.py

@ -3,6 +3,8 @@
# Copyright 2019-2020 Elouan Le Bars <elouan@coopiteasy.be> # Copyright 2019-2020 Elouan Le Bars <elouan@coopiteasy.be>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import ast
from openerp import fields, models, api from openerp import fields, models, api
@ -12,7 +14,7 @@ class ShiftConfigSettings(models.TransientModel):
card_support = fields.Boolean( card_support = fields.Boolean(
string="Scan cooperators cards instead of login for sheets validation", string="Scan cooperators cards instead of login for sheets validation",
default=False
default=False,
) )
default_task_type_id = fields.Many2one( default_task_type_id = fields.Many2one(
"beesdoo.shift.type", "beesdoo.shift.type",
@ -45,11 +47,10 @@ class ShiftConfigSettings(models.TransientModel):
@api.multi @api.multi
def get_default_card_support(self): def get_default_card_support(self):
return { return {
"card_support": (
"card_support": ast.literal_eval(
self.env["ir.config_parameter"].get_param( self.env["ir.config_parameter"].get_param(
"beesdoo_shift.card_support" "beesdoo_shift.card_support"
) )
== "True"
) )
} }

5
beesdoo_shift/security/group.xml

@ -30,10 +30,5 @@
<record model="ir.ui.menu" id="base.menu_board_root"> <record model="ir.ui.menu" id="base.menu_board_root">
<field name="groups_id" eval="[(6,0,[ref('group_shift_attendance_sheet')])]"/> <field name="groups_id" eval="[(6,0,[ref('group_shift_attendance_sheet')])]"/>
</record> </record>
<!-- <template id="website.user_navbar">
<field name="groups" eval="[(6,0,[ref('group_shift_attendance_sheet')])]"/>
</template> -->
</data> </data>
</odoo> </odoo>

19
beesdoo_shift/wizard/validate_attendance_sheet.py

@ -1,4 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import ast
from openerp import _, api, exceptions, fields, models from openerp import _, api, exceptions, fields, models
from openerp.exceptions import UserError, ValidationError from openerp.exceptions import UserError, ValidationError
@ -18,11 +21,10 @@ class ValidateAttendanceSheet(models.TransientModel):
return self.env[sheet_model].browse(sheet_id) return self.env[sheet_model].browse(sheet_id)
def _get_card_support_setting(self): def _get_card_support_setting(self):
return (
return ast.literal_eval(
self.env["ir.config_parameter"].get_param( self.env["ir.config_parameter"].get_param(
"beesdoo_shift.card_support" "beesdoo_shift.card_support"
) )
== "True"
) )
@api.multi @api.multi
@ -36,7 +38,9 @@ class ValidateAttendanceSheet(models.TransientModel):
warning_message = "" warning_message = ""
if sheet: if sheet:
for added_shift in sheet.added_shift_ids: for added_shift in sheet.added_shift_ids:
is_regular_worker = added_shift.worker_id.working_mode == "regular"
is_regular_worker = (
added_shift.worker_id.working_mode == "regular"
)
is_compensation = added_shift.is_compensation is_compensation = added_shift.is_compensation
if is_regular_worker and not is_compensation: if is_regular_worker and not is_compensation:
@ -68,15 +72,18 @@ class ValidateAttendanceSheet(models.TransientModel):
login = fields.Char(string="Login") login = fields.Char(string="Login")
password = fields.Char(string="Password") password = fields.Char(string="Password")
barcode = fields.Char(string="Barcode") barcode = fields.Char(string="Barcode")
warning_regular_workers = fields.Text("Warning",
warning_regular_workers = fields.Text(
"Warning",
default=_get_warning_regular_workers, default=_get_warning_regular_workers,
help="Is any regular worker doing its regular shift as an added one ?"
help="Is any regular worker doing its regular shift as an added one ?",
) )
notes = fields.Text( notes = fields.Text(
"Notes about the attendance for Members Office", "Notes about the attendance for Members Office",
default=_get_default_notes, default=_get_default_notes,
) )
feedback = fields.Text("Comments about the shift", default=_get_default_feedback)
feedback = fields.Text(
"Comments about the shift", default=_get_default_feedback
)
worker_nb_feedback = fields.Selection( worker_nb_feedback = fields.Selection(
[ [
("not_enough", "Not enough"), ("not_enough", "Not enough"),

Loading…
Cancel
Save