Compare commits

...

10 Commits

Author SHA1 Message Date
Thibault Francois 4137864ca7
Update task.py 4 years ago
Thibault Francois c0484b2d94
Update my_shift_website_templates.xml 4 years ago
Thibault Francois ed097db682 [WIP] 4 4 years ago
Thibault Francois baf7775e1b [WIP] final wip to clean 4 years ago
Thibault Francois 30a5fc707e
[FIX] can unsubscribe 4 years ago
Thibault Francois fd3ae85656 [WIP] 2 4 years ago
odoo-pda ddf9296b23 [ADD] send (un)subscribed mail when worker is 4 years ago
odoo-pda 83304986e3 [FIX] open instead as draft doesnt exist anymore 4 years ago
Thibault Francois 785a7df304 [WIP] 4 years ago
Thibault Francois bd66a9808e [FIX] beesdoo_shift: dynamic selection field 4 years ago
  1. 13
      beesdoo_shift/models/cooperative_status.py
  2. 41
      beesdoo_shift/models/task.py
  3. 2
      beesdoo_shift/views/cooperative_status.xml
  4. 2
      beesdoo_website_shift/controllers/main.py
  5. 121
      beesdoo_website_shift/views/my_shift_website_templates.xml
  6. 3
      beesdoo_worker_status/models/cooperative_status.py
  7. 40
      beesdoo_worker_status/models/task.py
  8. 1
      macavrac_base/__init__.py
  9. 8
      macavrac_base/__manifest__.py
  10. 1
      macavrac_base/controllers/__init__.py
  11. 16
      macavrac_base/controllers/main.py
  12. 16
      macavrac_base/data/mail_template.xml
  13. 1746
      macavrac_base/i18n/fr_BE.po
  14. 1
      macavrac_base/models/__init__.py
  15. 285
      macavrac_base/models/planning.py
  16. 25
      macavrac_base/models/res_partner.py
  17. 191
      macavrac_base/views/shift.xml

13
beesdoo_shift/models/cooperative_status.py

@ -91,7 +91,7 @@ class CooperativeStatus(models.Model):
comodel_name="cooperative.exempt.reason", string="Exempt Reason"
)
status = fields.Selection(
selection=_get_status,
selection=lambda x: x._get_status(),
compute="_compute_status",
string="Cooperative Status",
store=True,
@ -106,11 +106,10 @@ class CooperativeStatus(models.Model):
)
# Specific to irregular
irregular_start_date = fields.Date() # TODO migration script
irregular_start_date = fields.Date()
irregular_absence_date = fields.Date()
irregular_absence_counter = (
fields.Integer()
) # TODO unsubscribe when reach -2
irregular_absence_counter = fields.Integer()
future_alert_date = fields.Date(compute="_compute_future_alert_date")
next_countdown_date = fields.Date(compute="_compute_next_countdown_date")
@ -273,7 +272,7 @@ class CooperativeStatus(models.Model):
if not journal:
journal = self.env["beesdoo.shift.journal"].create({"date": today})
domain = self._get_irregular_worker_domain(today=today)
domain = self._get_irregular_worker_domain(today)
irregular = self.search(domain)
for status in irregular:
delta = (today - status.irregular_start_date).days
@ -362,7 +361,7 @@ class CooperativeStatus(models.Model):
# Irregular Cron implementation #
###############################################
def _get_irregular_worker_domain(self):
def _get_irregular_worker_domain(self, today):
"""
return the domain the give the list
of valid irregular worker that should

41
beesdoo_shift/models/task.py

@ -28,7 +28,6 @@ class Task(models.Model):
def _get_color_mapping(self, state):
return {
"draft": 0,
"open": 1,
"done": 5,
"absent": 2,
@ -59,7 +58,7 @@ class Task(models.Model):
)
end_time = fields.Datetime(track_visibility="always", required=True)
state = fields.Selection(
selection=_get_selection_status,
selection=lambda x: x._get_selection_status(),
default="open",
required=True,
track_visibility="onchange",
@ -96,20 +95,6 @@ class Task(models.Model):
for rec in self:
rec.color = self._get_color_mapping(rec.state)
def _compensation_validation(self, task):
"""
Raise a validation error if the fields is_regular and
is_compensation are not properly set.
"""
if task.is_regular == task.is_compensation or not (
task.is_regular or task.is_compensation
):
raise ValidationError(
_(
"You must choose between Regular Shift or "
"Compensation Shift."
)
)
@api.constrains("state")
def _lock_future_task(self):
@ -122,30 +107,6 @@ class Task(models.Model):
)
)
@api.constrains("is_regular", "is_compensation")
def _check_compensation(self):
for task in self:
if task.working_mode == "regular":
self._compensation_validation(task)
@api.constrains("worker_id")
def _check_worker_id(self):
"""
When worker_id changes we need to check whether is_regular
and is_compensation are set correctly.
When worker_id is set to a worker that doesn't need field
is_regular and is_compensation, these two fields are set to
False.
"""
for task in self:
if task.working_mode == "regular":
self._compensation_validation(task)
else:
task.write({"is_regular": False, "is_compensation": False})
if task.worker_id:
if task.worker_id == task.replaced_id:
raise UserError(_("A worker cannot replace himself."))
def message_auto_subscribe(self, updated_fields, values=None):
self._add_follower(values)
return super(Task, self).message_auto_subscribe(

2
beesdoo_shift/views/cooperative_status.xml

@ -161,7 +161,7 @@
<field name="holiday_end_time"/>
<field name="alert_start_time"/>
<field name="extension_start_time"/>
<field name="status" widget="statusbar"/>
<field name="status" />
</tree>
</field>
</record>

2
beesdoo_website_shift/controllers/main.py

@ -446,7 +446,7 @@ class WebsiteShiftController(http.Controller):
shift.planning_id = main_shift.planning_id
shift.task_type_id = main_shift.task_type_id
shift.worker_id = main_shift.worker_id
shift.state = "draft"
shift.state = "open"
shift.super_coop_id = main_shift.super_coop_id
shift.color = main_shift.color
shift.is_regular = main_shift.is_regular

121
beesdoo_website_shift/views/my_shift_website_templates.xml

@ -30,15 +30,7 @@
<h2>
Worker status
<span t-att-class="'badge %s pull-right' % ('badge-success' if status.can_shop else 'badge-danger',)">
<span class="fa fa-shopping-cart"></span>
<t t-if="status.can_shop">
<span class="fa fa-check"></span>
</t>
<t t-if="not status.can_shop">
<span class="fa fa-times"></span>
</t>
</span>
<!-- TODO specific view -->
</h2>
</template>
@ -77,34 +69,19 @@
<template
id="shift_status_label"
name="Shift Status Label">
<span t-if="shift.state == 'draft'"
t-attf-class="badge badge-default {{label_css}}">
<t t-esc="shift.state"/>
</span>
<!-- TODO specific to beescoop -->
<span t-if="shift.state == 'done'"
t-attf-class="badge badge-success {{label_css}}">
<t t-esc="shift.state"/>
</span>
<span t-if="shift.state == 'absent_2'"
t-attf-class="badge badge-warning {{label_css}}">
<t t-esc="shift.state"/>
</span>
<span t-if="shift.state == 'absent_1'"
t-attf-class="badge badge-info {{label_css}}">
<t t-esc="shift.state"/>
</span>
<span t-if="shift.state == 'absent_0'"
t-attf-class="badge badge-info {{label_css}}">
<span t-if="shift.state == 'absent'"
t-attf-class="badge badge-danger {{label_css}}">
<t t-esc="shift.state"/>
</span>
<span t-if="shift.state == 'cancel'"
t-attf-class="badge badge-danger {{label_css}}">
t-attf-class="badge badge-warning {{label_css}}">
<t t-esc="shift.state"/>
</span>
@ -225,11 +202,12 @@
</div>
</div>
</t>
<t t-if="not past_shifts">
<div class="alert alert-info">
<strong>Info !</strong>
You don't have any past shift.
</div>
</t>
</template>
@ -237,77 +215,55 @@
id="available_shift_irregular_worker"
name="Available Shift for Irregular Worker"
>
<!-- Inherited View -->
<t t-foreach="shift_templates" t-as="shift_count_subscribed">
<t t-set="shift" t-value="shift_count_subscribed[0]"/>
<t t-set="count" t-value="shift_count_subscribed[1]"/>
<t t-set="is_subscribed" t-value="shift_count_subscribed[2]"/>
<t t-set="has_enough_workers" t-value="shift_count_subscribed[3]"/>
<t t-set="highlight_class"
t-value="'panel-warning' if not has_enough_workers else 'panel-default'"/>
<div t-att-class="'card mb-4 %s' % highlight_class">
<t t-set="highlight_class" t-value="'panel-warning' if not has_enough_workers else 'panel-default'"/>
<t t-set="need_super" t-value="shift.task_type_id.super_only" />
<t t-set="user_super" t-value="request.env.user.partner_id.super" />
<div t-att-class="'card mb-4 %s' % highlight_class" t-if="not need_super or (need_super and user_super)">
<div t-att-class="'card-header %s clearfix' % highlight_header_class">
<div class="pull-left">
<span t-field="shift.start_time"/>
-
<span t-field="shift.end_time"
t-options='{"format": "HH:mm"}'/>
<span t-field="shift.end_time" t-options="{&quot;format&quot;: &quot;HH:mm&quot;}"/>
</div>
<div class="badge badge-secondary pull-right"
t-if="count > 0">
<div class="badge badge-secondary pull-right" t-if="count &gt; 0">
<t t-esc="count"/>
space(s)
</div>
<div class="badge badge-secondary pull-right"
t-if="count == 0">
<div class="badge badge-secondary pull-right" t-if="count == 0">
full
</div>
</div>
<div class="card-body clearfix">
<t t-esc="shift.task_type_id.name"/>
<div class="badge badge-success pull-right"
t-if="is_subscribed">
Subscribed
<div class="badge badge-dark pull-right" t-if="is_subscribed">
Already Subscribed
</div>
<button
type="button"
class="btn btn-default btn-sm pull-right"
data-toggle="modal"
t-att-data-target="'#subscribe-shift-%s' % shift.id"
t-if="irregular_enable_sign_up and not is_subscribed"
>
<span class="fa fa-user-plus" aria-hidden="true"></span>
<button type="button" class="btn btn-primary btn-sm pull-right" data-toggle="modal" t-att-data-target="'#subscribe-shift-%s' % shift.id" t-if="irregular_enable_sign_up and not is_subscribed">
<span class="fa fa-user-plus" aria-hidden="true"/>
Subscribe
</button>
</div>
</div>
<!-- Subscribe check -->
<t t-foreach="shift_templates" t-as="shift_count_subscribed">
<t t-set="shift" t-value="shift_count_subscribed[0]"/>
<t t-set="count" t-value="shift_count_subscribed[1]"/>
<t t-set="is_subscribed" t-value="shift_count_subscribed[2]"/>
<div class="modal fade"
t-att-id="'subscribe-shift-%s' % shift.id" tabindex="-1"
role="dialog"
t-att-aria-labelledby="'subscribe-shift-%s-label' % shift.id">
<div class="modal fade" t-att-id="'subscribe-shift-%s' % shift.id" tabindex="-1" role="dialog" t-att-aria-labelledby="'subscribe-shift-%s-label' % shift.id">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close"
data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title"
t-att-id="'subscribe-shift-%s-label' % shift.id">
<h4 class="modal-title" t-att-id="'subscribe-shift-%s-label' % shift.id">
Please confirm subscription
</h4>
</div>
<div class="modal-body">
<span t-field="shift.start_time"/>
-
<span t-field="shift.end_time"
t-options='{"format": "HH:mm"}'/>
<span t-field="shift.end_time" t-options="{&quot;format&quot;: &quot;HH:mm&quot;}"/>
<br/>
<t t-esc="shift.task_type_id.name"/>
<br/>
@ -315,22 +271,17 @@
available space(s)
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default"
data-dismiss="modal">Close
<button type="button" class="btn btn-default" data-dismiss="modal">Close
</button>
<a class="btn btn-primary"
t-if="irregular_enable_sign_up"
t-att-href="'/shift/%s/subscribe?nexturl=%s' % (shift.id, nexturl)">
<a class="btn btn-primary" t-if="irregular_enable_sign_up" t-att-href="'/shift/%s/subscribe?nexturl=%s' % (shift.id, nexturl)">
Subscribe
</a>
</div>
</div>
</div>
</div>
</t>
</t>
</template>
<!-- Help Texts -->
@ -440,13 +391,7 @@
For the compensation shifts, subscribe like you do for a normal
shift.
</p>
<p class="h_irreg_autoextension">
<strong>Auto-Extension:</strong>
You didn't manage to do your compensation shifts in the delay but
you benefit from the auto-extension.
This is two more weeks to do your compensation shifts. You can shop.
If you don't do your compensation shifts, you'll be suspended.
</p>
<!-- TODO make the modif in herited view-->
<p class="h_irreg_unsubscribed">
<strong>Unsubscribed:</strong>
Your counter is negative and you haven't come to work for more than
@ -700,21 +645,7 @@
</label>
<t t-esc="status.sr"/>
</p>
<p t-if="status.next_countdown_date">
<label class="font-weight-bold">Next Countdown
Date:
</label>
<t t-esc="status.next_countdown_date"/>
</p>
<p t-if="status.future_alert_date">
<label class="font-weight-bold">Future Date of
Alert:
</label>
<t t-esc="status.future_alert_date"/>
</p>
<!-- TODO specific view for beescoop -->
<p t-if="status.irregular_absence_date">
<label class="font-weight-bold">Last Absence Date:
</label>

3
beesdoo_worker_status/models/cooperative_status.py

@ -320,8 +320,7 @@ class CooperativeStatus(models.Model):
# Irregular Cron implementation #
###############################################
def _get_irregular_worker_domain(self, **kwargs):
today = kwargs.get("today") or self.today
def _get_irregular_worker_domain(self, today):
return [
"&",
"&",

40
beesdoo_worker_status/models/task.py

@ -4,6 +4,46 @@ from odoo import fields, models
class Task(models.Model):
_inherit = "beesdoo.shift.shift"
@api.constrains("worker_id")
def _check_worker_id(self):
"""
When worker_id changes we need to check whether is_regular
and is_compensation are set correctly.
When worker_id is set to a worker that doesn't need field
is_regular and is_compensation, these two fields are set to
False.
"""
for task in self:
if task.working_mode == "regular":
self._compensation_validation(task)
else:
task.write({"is_regular": False, "is_compensation": False})
if task.worker_id:
if task.worker_id == task.replaced_id:
raise UserError(_("A worker cannot replace himself."))
def _compensation_validation(self, task):
"""
Raise a validation error if the fields is_regular and
is_compensation are not properly set.
"""
if task.is_regular == task.is_compensation or not (
task.is_regular or task.is_compensation
):
raise ValidationError(
_(
"You must choose between Regular Shift or "
"Compensation Shift."
)
)
@api.constrains("is_regular", "is_compensation")
def _check_compensation(self):
for task in self:
if task.working_mode == "regular":
self._compensation_validation(task)
#################################
# State Definition #
#################################

1
macavrac_base/__init__.py

@ -1 +1,2 @@
from . import models
from . import controllers

8
macavrac_base/__manifest__.py

@ -7,8 +7,12 @@
"author": "Patricia Daloze, Coop IT Easy SCRLfs",
"category": "Sales",
"version": "12.0.1.0.0",
"depends": ["beesdoo_shift", "contacts"],
"data": ["views/res_partner.xml"],
"depends": ["beesdoo_shift", "beesdoo_website_shift", "contacts"],
"data": [
"data/mail_template.xml",
"views/res_partner.xml",
"views/shift.xml",
],
"installable": True,
"license": "AGPL-3",
}

1
macavrac_base/controllers/__init__.py

@ -0,0 +1 @@
from . import main

16
macavrac_base/controllers/main.py

@ -0,0 +1,16 @@
from odoo import http
from odoo.http import request
from werkzeug.exceptions import Forbidden
class WebsiteMacavracShiftController(http.Controller):
@http.route("/shift/<int:shift_id>/unsubscribe", auth="user", website=True)
def unsubscribe_to_shift(self, shift_id=-1, **kw):
shift = request.env["beesdoo.shift.shift"].sudo().browse(shift_id)
# Get current user
if request.env.user.partner_id != shift.worker_id or not shift.can_unsubscribe:
raise Forbidden()
shift.worker_id = False
return request.redirect(kw["nexturl"])

16
macavrac_base/data/mail_template.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Mail template are declared in a NOUPDATE block
so users can freely customize/delete them -->
<data noupdate="1">
<record id="email_template_shift_subscribed" model="mail.template">
<field name="name">Shift Subscribed</field>
<field name="model_id" ref="model_beesdoo_shift_shift"/>
</record>
<record id="email_template_shift_unsubscribed" model="mail.template">
<field name="name">Shift Unsubscribed</field>
<field name="model_id" ref="model_beesdoo_shift_shift"/>
</record>
</data>
</odoo>

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 planning

285
macavrac_base/models/planning.py

@ -0,0 +1,285 @@
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):
now = datetime.now()
ICP = self.env["ir.config_parameter"].sudo()
max_hours = int(ICP.get_param("max_hours_to_unsubscribe", 2))
for rec in self:
if now > rec.start_time or rec.state != 'open':
rec.can_unsubscribe = False
else:
delta = (rec.start_time - now)
delta = delta.seconds / 3600.0 + delta.days * 24
rec.can_unsubscribe = delta >= max_hours
# def write(self, vals):
# if 'worker_id' in vals:
# template_unsubscribed = self.env.ref("macavrac_base.email_template_shift_unsubscribed")
# template_subscribed = self.env.ref("macavrac_base.email_template_shift_subscribed")
# new_worker_id = self.env['beesdoo.shift.shift'].browse(vals.get('worker_id'))
# for record in self:
# old_worker_id = record.worker_id
# if old_worker_id:
# template_unsubscribed.send_mail(record.id)
# if new_worker_id and old_worker_id != new_worker_id:
# res = super(Task, record).write(vals)
# template_subscribed.send_mail(record.id)
# return super(Task, self).write(vals)
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:
#TODO fix infinite loop
rec.future_alert_date = False
continue
# 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:
#TODO fix infinite loop
rec.next_countdown_date = False
continue
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,
related="",
)
need_referent = fields.Boolean(
compute="_compute_need_referent",
search="_search_need_referent",
string="Need Referent",
readonly=True,
)
@api.depends("share_qty")
def _compute_share_amount(self):
@ -70,10 +76,21 @@ class Partner(models.Model):
@api.depends("cooperator_type")
def _compute_is_worker(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):
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:
return [("cooperator_type", "!=", "share_b")]
return []

191
macavrac_base/views/shift.xml

@ -0,0 +1,191 @@
<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>
<template id="my_shift" name="Shifts for Irregular Workers"
inherit_id="beesdoo_website_shift.my_shift_next_shifts">
<xpath expr="//t[@t-esc='shift.task_type_id.name']" position="after">
<button type="button"
class="btn btn-danger 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>
</xpath>
<xpath expr="//div[@t-if='shift.super_coop_id.name']/.." position="after">
<t t-foreach="subscribed_shifts" t-as="shift">
<div class="modal fade"
t-att-id="'unsubscribe-shift-%s' % shift.id" tabindex="-1"
role="dialog"
t-att-aria-labelledby="'unsubscribe-shift-%s-label' % shift.id">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title"
t-att-id="'subscribe-shift-%s-label' % shift.id">
Please confirm unsubscriptions
</h4>
</div>
<div class="modal-body">
<span t-field="shift.start_time"/>
-
<span t-field="shift.end_time"
t-options='{"format": "HH:mm"}'/>
<br/>
<t t-esc="shift.task_type_id.name"/>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default"
data-dismiss="modal">Close
</button>
<a class="btn btn-primary"
t-if="irregular_enable_sign_up"
t-att-href="'/shift/%s/unsubscribe?nexturl=%s' % (shift.id, nexturl)">
Unsubscribe
</a>
</div>
</div>
</div>
</div>
</t>
</xpath>
</template>
</odoo>
Loading…
Cancel
Save