Browse Source

[MIG] b_shift : change settings to fit 12.0 requirements

pull/143/head
Elouan Le Bars 5 years ago
parent
commit
b013e1524b
  1. 2
      beesdoo_shift/__manifest__.py
  2. 4
      beesdoo_shift/data/system_parameter.xml
  3. 2
      beesdoo_shift/models/__init__.py
  4. 12
      beesdoo_shift/models/attendance_sheet.py
  5. 10
      beesdoo_shift/models/cooperative_status.py
  6. 2
      beesdoo_shift/models/planning.py
  7. 53
      beesdoo_shift/models/res_config_settings.py
  8. 2
      beesdoo_shift/models/task.py
  9. 16
      beesdoo_shift/tests/test_beesdoo_shift.py
  10. 134
      beesdoo_shift/views/res_config_settings_view.xml
  11. 91
      beesdoo_shift/views/res_config_view.xml

2
beesdoo_shift/__manifest__.py

@ -23,7 +23,7 @@
"security/group.xml",
"security/ir.model.access.csv",
"views/task_template.xml",
"views/res_config_view.xml",
"views/res_config_settings_view.xml",
"views/task.xml",
"views/planning.xml",
"views/cooperative_status.xml",

4
beesdoo_shift/data/system_parameter.xml

@ -39,8 +39,8 @@
<field name="key">beesdoo_shift.attendance_sheet_generation_interval</field>
<field name="value">15</field>
</record>
<record id="beesdoo_shift.default_task_type_id" model="ir.config_parameter">
<field name="key">beesdoo_shift.default_task_type_id</field>
<record id="beesdoo_shift.task_type_default_id" model="ir.config_parameter">
<field name="key">beesdoo_shift.task_type_default_id</field>
<field name="value">1</field>
</record>
</odoo>

2
beesdoo_shift/models/__init__.py

@ -1,5 +1,5 @@
from . import attendance_sheet
from . import planning
from . import res_config
from . import res_config_settings
from . import task
from . import cooperative_status

12
beesdoo_shift/models/attendance_sheet.py

@ -15,9 +15,9 @@ class AttendanceSheetShift(models.AbstractModel):
_order = "task_type_id, worker_name"
@api.model
def default_task_type_id(self):
parameters = self.env["ir.config_parameter"]
id = int(parameters.get_param("beesdoo_shift.default_task_type_id", default=1))
def task_type_default_id(self):
parameters = self.env["ir.config_parameter"].sudo()
id = int(parameters.get_param("beesdoo_shift.task_type_default_id", default=1))
task_types = self.env["beesdoo.shift.type"]
return task_types.browse(id)
@ -46,7 +46,7 @@ class AttendanceSheetShift(models.AbstractModel):
)
worker_name = fields.Char(related="worker_id.name", store=True)
task_type_id = fields.Many2one(
"beesdoo.shift.type", string="Task Type", default=default_task_type_id
"beesdoo.shift.type", string="Task Type", default=task_type_default_id
)
working_mode = fields.Selection(
related="worker_id.working_mode", string="Working Mode"
@ -374,7 +374,7 @@ class AttendanceSheet(models.Model):
# Added shift creation
self.added_shift_ids |= self.added_shift_ids.new(
{
"task_type_id": self.added_shift_ids.default_task_type_id(),
"task_type_id": self.added_shift_ids.task_type_default_id(),
"state": "done",
"attendance_sheet_id": self._origin.id,
"worker_id": worker.id,
@ -591,7 +591,7 @@ class AttendanceSheet(models.Model):
sheets = self.env["beesdoo.shift.sheet"]
current_time = datetime.now()
generation_interval_setting = int(
self.env["ir.config_parameter"].get_param(
self.env["ir.config_parameter"].sudo().get_param(
"beesdoo_shift.attendance_sheet_generation_interval"
)
)

10
beesdoo_shift/models/cooperative_status.py

@ -100,9 +100,9 @@ class CooperativeStatus(models.Model):
'irregular_absence_counter', 'temporary_exempt_start_date',
'temporary_exempt_end_date', 'resigning', 'cooperator_id.subscribed_shift_ids')
def _compute_status(self):
alert_delay = int(self.env['ir.config_parameter'].get_param('alert_delay', 28))
grace_delay = int(self.env['ir.config_parameter'].get_param('default_grace_delay', 10))
update = int(self.env['ir.config_parameter'].get_param('always_update', False))
alert_delay = int(self.env['ir.config_parameter'].sudo().get_param('alert_delay', 28))
grace_delay = int(self.env['ir.config_parameter'].sudo().get_param('default_grace_delay', 10))
update = int(self.env['ir.config_parameter'].sudo().get_param('always_update', False))
for rec in self:
if update or not rec.today:
rec.status = 'ok'
@ -228,7 +228,7 @@ class CooperativeStatus(models.Model):
def _set_regular_status(self, grace_delay, alert_delay):
self.ensure_one()
counter_unsubscribe = int(self.env['ir.config_parameter'].get_param('regular_counter_to_unsubscribe', -4))
counter_unsubscribe = int(self.env['ir.config_parameter'].sudo().get_param('regular_counter_to_unsubscribe', -4))
ok = self.sr >= 0 and self.sc >= 0
grace_delay = grace_delay + self.time_extension
@ -270,7 +270,7 @@ class CooperativeStatus(models.Model):
self.can_shop = True
def _set_irregular_status(self, grace_delay, alert_delay):
counter_unsubscribe = int(self.env['ir.config_parameter'].get_param('irregular_counter_to_unsubscribe', -3))
counter_unsubscribe = int(self.env['ir.config_parameter'].sudo().get_param('irregular_counter_to_unsubscribe', -3))
self.ensure_one()
ok = self.sr >= 0
grace_delay = grace_delay + self.time_extension

2
beesdoo_shift/models/planning.py

@ -59,7 +59,7 @@ class Planning(models.Model):
@api.model
def _generate_next_planning(self):
config = self.env['ir.config_parameter']
config = self.env['ir.config_parameter'].sudo()
last_seq = int(config.get_param('last_planning_seq', 0))
date = config.get_param('next_planning_date', 0)

53
beesdoo_shift/models/res_config.py → beesdoo_shift/models/res_config_settings.py

@ -1,4 +1,3 @@
# Copyright 2019-2020 Elouan Le Bars <elouan@coopiteasy.be>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
@ -7,36 +6,37 @@ import ast
from odoo import fields, models, api
class ShiftConfigSettings(models.TransientModel):
_name = "beesdoo.shift.config.settings"
class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"
card_support = fields.Boolean(
string="Scan cooperators cards instead of login for sheets validation",
default=False,
config_parameter="beesdoo_shift.card_support",
)
default_task_type_id = fields.Many2one(
task_type_default_id = fields.Many2one(
"beesdoo.shift.type",
string="Default Task Type",
help="Default task type for attendance sheet pre-filling",
required=True,
default=False,
)
attendance_sheet_generation_interval = fields.Integer(
string="Time interval for attendance sheet generation",
help="Time interval expressed in minutes",
required=True,
config_parameter="beesdoo_shift.attendance_sheet_generation_interval",
)
@api.multi
def set_params(self):
self.ensure_one()
parameters = self.env["ir.config_parameter"]
def set_values(self):
super(ResConfigSettings, self).set_values()
parameters = self.env["ir.config_parameter"].sudo()
parameters.set_param(
"beesdoo_shift.card_support", str(self.card_support),
)
parameters.set_param(
"beesdoo_shift.default_task_type_id",
str(self.default_task_type_id.id),
"beesdoo_shift.task_type_default_id",
str(self.task_type_default_id.id),
)
parameters.set_param(
"beesdoo_shift.attendance_sheet_generation_interval",
@ -44,31 +44,18 @@ class ShiftConfigSettings(models.TransientModel):
)
@api.multi
def get_default_card_support(self):
return {
"card_support": ast.literal_eval(
def get_values(self):
res = super(ResConfigSettings, self).get_values()
res.update(
card_support=ast.literal_eval(
self.env["ir.config_parameter"].get_param(
"beesdoo_shift.card_support"
)
)
}
@api.multi
def get_default_task_type_id(self):
return {
"default_task_type_id": int(
self.env["ir.config_parameter"].get_param(
"beesdoo_shift.default_task_type_id"
)
)
}
@api.multi
def get_default_attendance_sheet_generation_interval(self):
return {
"attendance_sheet_generation_interval": int(
),
),
task_type_default_id=int(
self.env["ir.config_parameter"].get_param(
"beesdoo_shift.attendance_sheet_generation_interval"
"beesdoo_shift.task_type_default_id"
)
),
)
}
return res

2
beesdoo_shift/models/task.py

@ -213,7 +213,7 @@ class Task(models.Model):
def _update_state(self, new_state):
self.ensure_one()
self._revert()
update = int(self.env['ir.config_parameter'].get_param('always_update', False))
update = int(self.env['ir.config_parameter'].sudo().get_param('always_update', False))
data = {}

16
beesdoo_shift/tests/test_beesdoo_shift.py

@ -20,8 +20,8 @@ class TestBeesdooShift(TransactionCase):
]
self.shift_expected_model = self.env["beesdoo.shift.sheet.expected"]
self.shift_added_model = self.env["beesdoo.shift.sheet.added"]
self.default_task_type_id = self.env["ir.config_parameter"].get_param(
"beesdoo_shift.default_task_type_id"
self.task_type_default_id = self.env["ir.config_parameter"].sudo().get_param(
"beesdoo_shift.task_type_default_id"
)
self.current_time = datetime.now()
@ -165,16 +165,16 @@ class TestBeesdooShift(TransactionCase):
for task_type in (self.task_type_1, self.task_type_2):
# Setting default value
setting_wizard_1 = self.setting_wizard.create(
{"default_task_type_id": task_type.id}
{"task_type_default_id": task_type.id}
)
setting_wizard_1.execute()
param_id = self.env["ir.config_parameter"].get_param(
"beesdoo_shift.default_task_type_id"
param_id = self.env["ir.config_parameter"].sudo().get_param(
"beesdoo_shift.task_type_default_id"
)
self.assertEqual(int(param_id), task_type.id)
# Check propagation on attendance sheet shifts
self.assertEqual(
self.attendance_sheet_shift_model.default_task_type_id(),
self.attendance_sheet_shift_model.task_type_default_id(),
task_type,
)
@ -184,7 +184,7 @@ class TestBeesdooShift(TransactionCase):
# Set generation interval setting
setting_wizard_1 = self.setting_wizard.create(
{
"default_task_type_id": self.task_type_1.id,
"task_type_default_id": self.task_type_1.id,
"attendance_sheet_generation_interval": 15,
}
)
@ -300,7 +300,7 @@ class TestBeesdooShift(TransactionCase):
self.assertEqual(shift.state, "done")
self.assertEqual(
shift.task_type_id,
self.attendance_sheet_shift_model.default_task_type_id(),
self.attendance_sheet_shift_model.task_type_default_id(),
)
if shift.working_mode == "regular":
self.assertTrue(shift.is_compensation)

134
beesdoo_shift/views/res_config_settings_view.xml

@ -0,0 +1,134 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2019-2020 Elouan Le Bars <elouan@coopiteasy.be>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<data>
<record model="ir.ui.view" id="daynumber_view_tree">
<field name="name">Day Number List</field>
<field name="model">beesdoo.shift.daynumber</field>
<field name="arch" type="xml">
<tree editable="top">
<field name="name" />
<field name="number" />
<field name="active" />
</tree>
</field>
</record>
<record model="ir.ui.view" id="type_view_tree">
<field name="name">Shift Type List</field>
<field name="model">beesdoo.shift.type</field>
<field name="arch" type="xml">
<tree>
<field name="name" />
<field name="description" />
<field name="active" />
</tree>
</field>
</record>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.beesdoo.shift</field>
<field name="model">res.config.settings</field>
<field name="priority" eval="50"/>
<field name="inherit_id" ref="base.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[hasclass('settings')]" position="inside">
<div class="app_settings_block" data-string="Shifts Management" string="Shifts Management" data-key="shifts_management" groups="beesdoo_shift.group_cooperative_admin">
<field name="has_accounting_entries" invisible="1"/>
<h2>Attendance Sheets</h2>
<div class="row mt16 o_settings_container">
<div class="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="card_support"/>
</div>
<div class="o_setting_right_pane">
<label for="card_support" string="Scan cards for validation" />
<div class="text-muted">
If not checked, user credentials are asked.
</div>
</div>
</div>
</div>
<div class="row mt16 o_settings_container">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_right_pane">
<span class="o_form_label">Attendance Sheets Generation Interval</span>
<div class="text-muted">
Generate attendance sheets before shifts start.
</div>
<div class="content-group">
<div class="mt16 row">
<label for="attendance_sheet_generation_interval" string="Interval (minutes)" class="col-3 col-lg-3 o_light_label"/>
<field name="attendance_sheet_generation_interval" class="oe_inline" required="1"/>
</div>
</div>
</div>
</div>
</div>
<div class="row mt16 o_settings_container">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_right_pane">
<span class="o_form_label">Default Task Type</span>
<div class="text-muted">
For attendance sheets automatic pre-filling.
</div>
<div class="content-group">
<div class="mt16 row">
<label for="task_type_default_id" string="Default Task Type" class="col-3 col-lg-3 o_light_label"/>
<field name="task_type_default_id" class="oe_inline" required="1"/>
</div>
</div>
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>
<menuitem name="Configuration"
id="menu_configuration_top"
parent="menu_root"
groups="beesdoo_shift.group_planning_management"
sequence="21"
/>
<record model="ir.actions.act_window" id="action_day_number">
<field name="name">Day Number</field>
<field name="res_model">beesdoo.shift.daynumber</field>
<field name="view_mode">tree</field>
</record>
<menuitem name="Shift Day" id="menu_configuration_day"
parent="menu_configuration_top" action="action_day_number" />
<record model="ir.actions.act_window" id="action_type">
<field name="name">Shift Type</field>
<field name="res_model">beesdoo.shift.type</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem name="Shift Type" id="menu_configuration_type"
parent="menu_configuration_top" action="action_type" />
<record model="ir.actions.act_window" id="action_shift_settings">
<field name="name">Settings</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.config.settings</field>
<field name="view_mode">form</field>
<field name="target">inline</field>
<field name="context">{'module' : 'beesdoo_shift'}</field>
</record>
<menuitem name="Shift Settings"
id="menu_shift_settings"
parent="menu_configuration_top"
action="action_shift_settings"
groups="beesdoo_shift.group_cooperative_admin"
/>
</data>
</odoo>

91
beesdoo_shift/views/res_config_view.xml

@ -1,91 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2019-2020 Elouan Le Bars <elouan@coopiteasy.be>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<data>
<record model="ir.ui.view" id="daynumber_view_tree">
<field name="name">Day Number List</field>
<field name="model">beesdoo.shift.daynumber</field>
<field name="arch" type="xml">
<tree editable="top">
<field name="name" />
<field name="number" />
<field name="active" />
</tree>
</field>
</record>
<record model="ir.ui.view" id="type_view_tree">
<field name="name">Shift Type List</field>
<field name="model">beesdoo.shift.type</field>
<field name="arch" type="xml">
<tree>
<field name="name" />
<field name="description" />
<field name="active" />
</tree>
</field>
</record>
<record model="ir.ui.view" id="shift_settings_view_form">
<field name="name">Shifts Configuration Form</field>
<field name="model">beesdoo.shift.config.settings</field>
<field name="arch" type="xml">
<form string="Settings" class="oe_form_configuration" create="false" delete="false" >
<header>
<button string="Apply" type="object" name="execute" class="oe_highlight"/>
<button string="Cancel" type="object" name="cancel" class="oe_link"/>
</header>
<separator string="General Settings"/>
<group name="Attendance Sheets">
<field name="card_support"/>
<field name="attendance_sheet_generation_interval"/>
<field name="default_task_type_id"/>
</group>
</form>
</field>
</record>
<menuitem name="Configuration"
id="menu_configuration_top"
parent="menu_root"
groups="beesdoo_shift.group_planning_management"
sequence="21"
/>
<record model="ir.actions.act_window" id="action_day_number">
<field name="name">Day Number</field>
<field name="res_model">beesdoo.shift.daynumber</field>
<field name="view_mode">tree</field>
</record>
<menuitem name="Shift Day" id="menu_configuration_day"
parent="menu_configuration_top" action="action_day_number" />
<record model="ir.actions.act_window" id="action_type">
<field name="name">Shift Type</field>
<field name="res_model">beesdoo.shift.type</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem name="Shift Type" id="menu_configuration_type"
parent="menu_configuration_top" action="action_type" />
<record model="ir.actions.act_window" id="action_shift_settings">
<field name="name">Settings</field>
<field name="res_model">beesdoo.shift.config.settings</field>
<field name="view_mode">form</field>
<field name="target">inline</field>
</record>
<menuitem name="Settings"
id="menu_shift_settings"
parent="menu_configuration_top"
action="action_shift_settings"
groups="beesdoo_shift.group_cooperative_admin"
/>
</data>
</odoo>
Loading…
Cancel
Save