Browse Source

[WIP]

12.0-macavrac-prod
Thibault Francois 4 years ago
parent
commit
785a7df304
  1. 10
      beesdoo_website_shift/views/my_shift_website_templates.xml
  2. 5
      macavrac_base/__manifest__.py
  3. 1746
      macavrac_base/i18n/fr_BE.po
  4. 1
      macavrac_base/models/__init__.py
  5. 257
      macavrac_base/models/planning.py
  6. 25
      macavrac_base/models/res_partner.py
  7. 140
      macavrac_base/views/shift.xml

10
beesdoo_website_shift/views/my_shift_website_templates.xml

@ -141,6 +141,16 @@
</div> </div>
<div class="card-body clearfix"> <div class="card-body clearfix">
<t t-esc="shift.task_type_id.name"/> <t t-esc="shift.task_type_id.name"/>
<button
type="button"
class="btn btn-default btn-sm pull-right"
data-toggle="modal"
t-att-data-target="'#unsubscribe-shift-%s' % shift.id"
t-if="shift.can_unsubscribe"
>
<span class="fa fa-user-plus" aria-hidden="true"></span>
Unsubscribe
</button>
<button <button
type="button" type="button"
class="btn btn-default btn-sm pull-right" class="btn btn-default btn-sm pull-right"

5
macavrac_base/__manifest__.py

@ -8,7 +8,10 @@
"category": "Sales", "category": "Sales",
"version": "12.0.1.0.0", "version": "12.0.1.0.0",
"depends": ["beesdoo_shift", "contacts"], "depends": ["beesdoo_shift", "contacts"],
"data": ["views/res_partner.xml"],
"data": [
"views/res_partner.xml",
"views/shift.xml",
],
"installable": True, "installable": True,
"license": "AGPL-3", "license": "AGPL-3",
} }

1746
macavrac_base/i18n/fr_BE.po
File diff suppressed because it is too large
View File

1
macavrac_base/models/__init__.py

@ -1 +1,2 @@
from . import res_partner from . import res_partner
from . import planning

257
macavrac_base/models/planning.py

@ -0,0 +1,257 @@
from datetime import datetime
from odoo import api, models, fields
from odoo.addons.beesdoo_shift.models.cooperative_status import add_days_delta
class TaskType(models.Model):
_inherit = "beesdoo.shift.type"
super_only = fields.Boolean('Referent Only')
class TaskTemplate(models.Model):
_inherit = 'beesdoo.shift.template'
super_only = fields.Boolean(related="task_type_id.super_only")
shift_presence_value = fields.Float(default=1.0)
class WizardSubscribe(models.TransientModel):
_inherit = 'beesdoo.shift.subscribe'
def _get_mode(self):
partner = self.env["res.partner"].browse(self._context.get("active_id"))
return partner.working_mode or 'irregular'
working_mode = fields.Selection(selection=[
("irregular", "worker"),
("exempt", "Exempted"),
], default=_get_mode)
class Task(models.Model):
_inherit = 'beesdoo.shift.shift'
can_unsubscribe = fields.Boolean(compute="_compute_can_unsubscribe")
super_only = fields.Boolean(related="task_type_id.super_only")
def _get_selection_status(self):
return [
("open","Confirmed"),
("done","Attended"),
("absent","Absent"),
("cancel","Cancelled")
]
def _get_counter_date_state_change(self, new_state):
"""
Return the cooperator_status of the cooperator that need to be
change and data that need to be change. It does not perform the
change directly. The cooperator_status will be changed by the
_change_counter function.
Check has been done to ensure that worker is legitimate.
"""
data = {}
status = self.worker_id.cooperative_status_ids[0]
if new_state == "done":
data['sr'] = self.task_template_id.shift_presence_value or 1.0
return data, status
def _compute_can_unsubscribe(self):
for rec in self:
print(datetime.now())
rec.can_unsubscribe = True
class CooperativeStatus(models.Model):
_inherit = 'cooperative.status'
def _get_status(self):
return [
("ok", "Up to Date"),
("alert", "Alerte"),
("suspended", "Suspended"),
("exempted", "Exempted"),
("unsubscribed", "Unsubscribed"),
("resigning", "Resigning"),
]
# TODO auto init for automatic migration
sr = fields.Float()
future_alert_date = fields.Date(compute="_compute_future_alert_date")
next_countdown_date = fields.Date(compute="_compute_next_countdown_date")
########################################################
# Method to override #
# To define the behavior of the status #
# #
# By default: everyone is always up to date #
########################################################
##############################
# Computed field section #
##############################
def _next_countdown_date(self, irregular_start_date, today):
"""
Return the next countdown date given irregular_start_date and
today dates.
This does not take holiday and other status into account.
"""
delta = (today - irregular_start_date).days
if not delta % self._period:
return today
return add_days_delta(today, self._period - (delta % self._period))
@api.depends(
"today",
"sr",
"temporary_exempt_start_date",
"temporary_exempt_end_date",
)
def _compute_future_alert_date(self):
"""Compute date before which the worker is up to date"""
for rec in self:
# Only for irregular worker
# Alert start time already set
real_today = rec.today
if rec.alert_start_time:
rec.future_alert_date = False
elif rec.working_mode != "irregular" or not rec.irregular_start_date:
rec.future_alert_date = False
else:
date = rec.today
counter = rec.sr
next_countdown_date = False
while counter >= 0:
next_countdown_date = self._next_countdown_date(rec.irregular_start_date, date)
rec.today = next_countdown_date
if rec.status != 'exempted':
counter -= 1
rec.today = real_today
date = add_days_delta(next_countdown_date, 1)
rec.future_alert_date = next_countdown_date
rec.today = real_today
@api.depends(
"today",
"irregular_start_date",
"holiday_start_time",
"holiday_end_time",
"temporary_exempt_start_date",
"temporary_exempt_end_date",
)
def _compute_next_countdown_date(self):
"""
Compute the following countdown date. This date is the date when
the worker will see his counter changed du to the cron. This
date is like the birthday date of the worker that occurred each
PERIOD.
"""
for rec in self:
real_today = rec.today
# Only for irregular worker
if rec.working_mode != "irregular" or not rec.irregular_start_date:
rec.next_countdown_date = False
else:
next_countdown_date = rec.today
while True:
next_countdown_date = self._next_countdown_date(rec.irregular_start_date, next_countdown_date)
rec.today = next_countdown_date
if rec.status != 'exempted':
rec.next_countdown_date = next_countdown_date
rec.today = real_today
break
else:
next_countdown_date = add_days_delta(next_countdown_date, 1)
#####################################
# Status Change implementation #
#####################################
def _get_regular_status(self):
"""
Return the value of the status
for the regular worker
"""
ICP = self.env["ir.config_parameter"].sudo()
suspended_count = int(ICP.get_param("suspended_count", -2))
unsubscribed_count = int(ICP.get_param("unsubscribed_count", -4))
if (self.temporary_exempt_start_date
and self.temporary_exempt_end_date
and self.today >= self.temporary_exempt_start_date
and self.today <= self.temporary_exempt_end_date
):
return 'exempted'
if self.sr >= 0:
return 'ok'
if self.sr <= unsubscribed_count:
return 'unsubscribed'
if self.sr <= suspended_count:
return 'suspended'
if self.sr < 0:
return 'alert'
return 'ok'
def _get_irregular_status(self):
"""
Return the value of the status
for the irregular worker
"""
return self._get_regular_status()
def _state_change(self, new_state):
"""
Hook to watch change in the state
"""
self.ensure_one()
if new_state == "unsubscribed" or new_state == "resigning":
# Remove worker from task_templates
self.cooperator_id.sudo().write(
{"subscribed_shift_ids": [(5, 0, 0)]}
)
# Remove worker from supercoop in task_templates
task_tpls = self.env["beesdoo.shift.template"].search(
[("super_coop_id", "in", self.cooperator_id.user_ids.ids)]
)
task_tpls.write({"super_coop_id": False})
# Remove worker for future tasks (remove also supercoop)
self.env["beesdoo.shift.shift"].sudo().unsubscribe_from_today(
[self.cooperator_id.id], now=fields.Datetime.now()
)
if new_state == "alert":
self.write({"alert_start_time": self.today})
def _change_counter(self, data):
"""
Call when a shift state is changed
use data generated by _get_counter_date_state_change
"""
self.sr += data.get("sr", 0)
###############################################
###### Irregular Cron implementation ##########
###############################################
def _get_irregular_worker_domain(self, today):
"""
return the domain the give the list
of valid irregular worker that should
get their counter changed by the cron
"""
return [
("status", "not in", ["unsubscribed", "exempted", "resigning"]),
("irregular_start_date", "!=", False),
]
def _change_irregular_counter(self):
"""
Define how the counter will change
for the irregular worker
where today - start_date is a multiple of the period
by default 28 days
"""
self.sr -= 1

25
macavrac_base/models/res_partner.py

@ -59,6 +59,12 @@ class Partner(models.Model):
readonly=True, readonly=True,
related="", related="",
) )
need_referent = fields.Boolean(
compute="_compute_need_referent",
search="_search_need_referent",
string="Need Referent",
readonly=True,
)
@api.depends("share_qty") @api.depends("share_qty")
def _compute_share_amount(self): def _compute_share_amount(self):
@ -70,10 +76,21 @@ class Partner(models.Model):
@api.depends("cooperator_type") @api.depends("cooperator_type")
def _compute_is_worker(self): def _compute_is_worker(self):
for rec in self: for rec in self:
rec.is_worker = rec.cooperator_type == "share_b"
rec.is_worker = rec.cooperator_type in ('share_a', 'share_b')
def _search_is_worker(self, operator, value): def _search_is_worker(self, operator, value):
if (operator == "=" and value) or (operator == "!=" and not value):
return [("cooperator_type", "=", "share_b")]
if (operator == '=' and value) or (operator == '!=' and not value):
return [('cooperator_type', 'in', ('share_a', 'share_b'))]
else:
return ['&', ('cooperator_type', '!=', 'share_a'), ('cooperator_type', '!=', 'share_b')]
@api.depends("super")
def _compute_need_referent(self):
for rec in self:
rec.need_referent = rec.super
def _search_need_referent(self, operator, value):
if (operator == '=' and value) or (operator == '!=' and not value):
return [('super', '=', True)]
else: else:
return [("cooperator_type", "!=", "share_b")]
return []

140
macavrac_base/views/shift.xml

@ -0,0 +1,140 @@
<odoo>
<record model="ir.ui.view" id="type_view_form_inherit">
<field name="name">Shift Type Form Inherit</field>
<field name="model">beesdoo.shift.type</field>
<field name="inherit_id" ref="beesdoo_shift.type_view_form" />
<field name="arch" type="xml">
<field name="name" position="after">
<field name="super_only" />
</field>
</field>
</record>
<record model="ir.ui.view" id="task_template_view_form_inherit">
<field name="name">Task Template Form Inherit</field>
<field name="model">beesdoo.shift.template</field>
<field name="inherit_id" ref="beesdoo_shift.task_template_view_form" />
<field name="arch" type="xml">
<field name="super_coop_id" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="task_type_id" position="after">
<field name="super_only" invisible="1" />
<field name="shift_presence_value" />
</field>
<field name="worker_ids" position="attributes">
<attribute name="domain">[("is_worker", "=", True), ('need_referent', '=', super_only)]</attribute>
</field>
</field>
</record>
<record model="ir.ui.view" id="task_view_form_inherit">
<field name="name">Task Form inherit</field>
<field name="inherit_id" ref="beesdoo_shift.task_view_form" />
<field name="model">beesdoo.shift.shift</field>
<field name="arch" type="xml">
<field name="super_coop_id" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="replaced_id" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="is_regular" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="is_compensation" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="task_type_id" position="after">
<field name="super_only" invisible="1" />
</field>
<field name="worker_id" position="attributes">
<attribute name="domain">[('cooperative_status_ids.status', 'not in', ('unsubscribed', 'resigning')), ('need_referent', '=', super_only)]</attribute>
</field>
</field>
</record>
<record model="ir.ui.view" id="coop_status_form_view_inherit">
<field name="name">Coop Status Form View Inherit</field>
<field name="inherit_id" ref="beesdoo_shift.coop_status_form_view" />
<field name="model">cooperative.status</field>
<field name="arch" type="xml">
<field name="irregular_start_date" position="attributes">
<attribute name="attrs" ></attribute>
<attribute name="string">Start date</attribute>
</field>
<field name="sc" position="attributes">
<attribute name="invisible" >1</attribute>
</field>
<field name="time_extension" position="attributes">
<attribute name="invisible" >1</attribute>
</field>
<field name="extension_start_time" position="attributes">
<attribute name="invisible" >1</attribute>
</field>
<field name="info_session" position="attributes">
<attribute name="invisible" >1</attribute>
</field>
<field name="info_session_date" position="attributes">
<attribute name="invisible" >1</attribute>
</field>
<field name="irregular_absence_counter" position="attributes">
<attribute name="invisible" >1</attribute>
</field>
<field name="irregular_absence_date" position="attributes">
<attribute name="invisible" >1</attribute>
</field>
<field name="holiday_start_time" position="attributes">
<attribute name="invisible" >1</attribute>
</field>
<field name="holiday_end_time" position="attributes">
<attribute name="invisible" >1</attribute>
</field>
</field>
</record>
<record model="ir.ui.view" id="super_coop_partner_inherited_view_form">
<field name="name">Partner Macavrac</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="beesdoo_shift.super_coop_partner_inherited_view_form"/>
<field name="priority">50</field>
<field name="arch" type="xml">
<button name="coop_subscribe" string="Subscribe to shift"
class="oe_highlight"
type="object"
groups="beesdoo_shift.group_shift_management"
attrs="{'invisible': [('is_worker', '=', False)]}"/>
<button name="auto_extension" position="attributes">
<attribute name="invisible">1</attribute>
</button>
<button name="manual_extension" position="attributes">
<attribute name="invisible">1</attribute>
</button>
<button name="register_holiday" position="attributes">
<attribute name="invisible">1</attribute>
</button>
</field>
</record>
<!-- Wizard view modification -->
<record model="ir.ui.view" id="subscribe_coop_wizard_view_form_inherit">
<field name="name">Subscribe Cooperator</field>
<field name="model">beesdoo.shift.subscribe</field>
<field name="inherit_id" ref="beesdoo_shift.subscribe_coop_wizard_view_form" />
<field name="arch" type="xml">
<field name="shift_id" position="attributes">
<attribute name="attrs"></attribute>
</field>
<field name="info_session" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="info_session_date" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="reset_compensation_counter" position="attributes">
<attribute name="invisible">1</attribute>
</field>
</field>
</record>
</odoo>
Loading…
Cancel
Save