Commit b9a6dc52 by François C.

Implements new La Cagette rules

parent 18714da9
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3
=========================
La Cagette specific rules
=========================
All shift template are FTOP type.
Every cooperative members is subscribing a FTOP shift template.
Every 28 days (4 weeks), every shift template subscriber losts 1 point.
If a cooperative member is not present to a due shift, she or he losts 1 point and has 2 makeups to do.
Every cooperative member move its regular shift to an other day.
When the coop. member counter reaches -2 points, the cooperative status is set to 'Suspended'.
When the coop. member counter reaches -3 points, the cooperatice status is set to 'Unsubscribed'
...@@ -6,22 +6,22 @@ ...@@ -6,22 +6,22 @@
Tuning membership rules""", Tuning membership rules""",
'description': """ 'description': """
Specific rules are beeing implemented
""", """,
'author': "fracolo", 'author': "fracolo/cooperatic",
'website': "https://lacagette-coop.fr", 'website': "https://lacagette-coop.fr",
# #
'category': 'Uncategorized', 'category': 'Uncategorized',
'version': '0.0.3', 'version': '0.0.4',
# any module necessary for this one to work correctly # any module necessary for this one to work correctly
'depends': ['base', 'coop_shift'], 'depends': ['base', 'coop_shift'],
# always loaded # always loaded
'data': [ 'data': [
'data/ir_cron.xml', 'data/ir_cron.xml',
# 'ir_config_parameter_data.xml' 'ir_config_parameter_data.xml'
], ],
'installable': True, 'installable': True,
} }
<?xml version="1.0"?>
<odoo noupdate="0">
<record id="makeups_to_do_if_missed_id" model="ir.config_parameter">
<field name="key">lacagette_membership.makeups_to_do_on_shift_missed</field>
<field name="value">2</field>
</record>
</odoo>
...@@ -18,4 +18,17 @@ ...@@ -18,4 +18,17 @@
<field name="active" eval="False"/> <field name="active" eval="False"/>
<field name="priority">2</field> <field name="priority">2</field>
</record> </record>
<record forcecreate="True" id="cron_process_target_status" model="ir.cron">
<field name="name">Process coop target status</field>
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">hours</field>
<field name="numbercall">-1</field>
<field name="doall" eval="True"/>
<field name="model" eval="'res.partner'"/>
<field name="function" eval="'run_process_target_status'"/>
<field name="args" eval="'()'"/>
<field name="active" eval="False"/>
<field name="priority">1</field>
</record>
</odoo> </odoo>
\ No newline at end of file
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from . import res_partner from . import res_partner
from . import shift_registration from . import shift_registration
\ No newline at end of file from . import shift_counter_event
...@@ -3,6 +3,11 @@ ...@@ -3,6 +3,11 @@
from openerp import _, api, models, fields from openerp import _, api, models, fields
import datetime import datetime
TARGET_STATUS_SELECTION = [
('unsubscribed', 'Unsubscribed'),
('suspended', 'Suspended')
]
class ResPartner(models.Model): class ResPartner(models.Model):
_inherit = 'res.partner' _inherit = 'res.partner'
...@@ -11,6 +16,28 @@ class ResPartner(models.Model): ...@@ -11,6 +16,28 @@ class ResPartner(models.Model):
"Number of make-ups to done", "Number of make-ups to done",
default= 0) default= 0)
target_status = fields.Selection(
selection=TARGET_STATUS_SELECTION, default='')
@api.model
def run_process_target_status(self):
"""Method called by cron task"""
# final_ftop_point, target_status
for p in self.env['res.partner']\
.search([('target_status', '!=', "")]):
new_values = {'target_status': "", "date_alert_stop": ""}
if p.final_ftop_point < 0:
new_values['cooperative_state'] = p.target_status
if new_values['cooperative_state'] == "unsubscribed":
"""
unlink model: "shift.template.registration"
to delete all future shifts linked to this coop.
"""
for streg in self.env['shift.template.registration']\
.search([('partner_id', '=', p.id)]):
streg.unlink()
p.update(new_values)
#@api.onchange('cooperativestate') : could be used only if it is called from client #@api.onchange('cooperativestate') : could be used only if it is called from client
@api.model @api.model
......
# -*- coding: utf-8 -*-
from openerp import _, api, models, fields
import logging
_logger = logging.getLogger(__name__)
class ShiftCounterEvent(models.Model):
_inherit = 'shift.counter.event'
def _update_partner_target_status(self, vals):
"""actions if point_qty is negative"""
if vals['point_qty'] < 0:
res_partner = self.env['res.partner'].search([('id', '=', vals['partner_id'])])
if res_partner:
points_before_removing_points = res_partner[0].final_ftop_point
points_after_removal = points_before_removing_points + vals['point_qty']
_logger.info("points_after_removal = %s", str(points_after_removal))
if points_after_removal <= -2:
target_status = 'suspended'
if points_after_removal < -2:
target_status = 'unsubscribed'
res_partner[0].update({'target_status': target_status})
@api.model
def write(self, vals):
res = super(ShiftCounterEvent, self).write(vals)
#_logger.info("Vals reçues = %s", str(vals))
self._update_partner_target_status(vals)
return res
@api.model
def create(self, vals):
self._update_partner_target_status(vals)
# _logger.info("Vals reçues creation = %s", str(vals))
return super(ShiftCounterEvent, self).create(vals)
\ No newline at end of file
...@@ -22,8 +22,11 @@ class ShiftRegistration(models.Model): ...@@ -22,8 +22,11 @@ class ShiftRegistration(models.Model):
res = super(ShiftRegistration, self).write(vals) res = super(ShiftRegistration, self).write(vals)
if 'state' in vals and vals['state'] == 'excused': if 'state' in vals and vals['state'] == 'excused':
if self.ids: if self.ids:
# it is the case when called from "absence cron job" run in external third-party
conf = self.env['ir.config_parameter']
to_add = conf.get_param("lacagette_membership.makeups_to_do_on_shift_missed")
for s in self.env['shift.registration']\ for s in self.env['shift.registration']\
.search([('id', 'in', self.ids)]): .search([('id', 'in', self.ids)]):
new_makeups_to_do = s.partner_id.makeups_to_do + 1 new_makeups_to_do = s.partner_id.makeups_to_do + to_add
s.partner_id.update({'makeups_to_do': new_makeups_to_do}) s.partner_id.update({'makeups_to_do': new_makeups_to_do})
return res return res
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment