Commit fb155821 by François C.

Membership parameters mangement to fit with many scenarii

parent a5f1a125
......@@ -7,6 +7,8 @@
'description': """
Specific rules are beeing implemented
lacagette_membership.absence_status can be excused or absent
""",
'author': "fracolo/cooperatic",
......@@ -14,12 +16,13 @@
#
'category': 'Uncategorized',
'version': '0.0.4',
'version': '0.0.5',
# any module necessary for this one to work correctly
'depends': ['base', 'coop_shift'],
'depends': ['base', 'coop_membership', 'coop_shift'],
# always loaded
'data': [
'security/ir.model.access.csv',
'data/ir_cron.xml',
'data/ir_config_parameter_data.xml'
],
......
......@@ -4,4 +4,25 @@
<field name="key">lacagette_membership.makeups_to_do_on_shift_missed</field>
<field name="value">2</field>
</record>
<record id="points_limit_to_get_suspended" model="ir.config_parameter">
<field name="key">lacagette_membership.points_limit_to_get_suspended</field>
<field name="value">-2</field>
</record>
<record id="points_limit_to_get_unsubscribed" model="ir.config_parameter">
<field name="key">lacagette_membership.points_limit_to_get_unsubscribed</field>
<field name="value">-3</field>
</record>
<record id="makeups_to_do_if_missed_id" model="ir.config_parameter">
<field name="key">lacagette_membership.absence_status</field>
<field name="value">excused</field>
</record>
<record id="extension_duration" model="ir.config_parameter">
<field name="key">lacagette_membership.extension_duration</field>
<field name="value">6 months</field>
</record>
<record id="max_successive_extensions" model="ir.config_parameter">
<field name="key">lacagette_membership.max_successive_extensions</field>
<field name="value">1</field>
</record>
</odoo>
......@@ -4,3 +4,4 @@ from . import res_partner
from . import shift_registration
from . import shift_counter_event
from . import shift_shift
from . import member_state_change
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html
from openerp import fields, models
class MembersStateChange(models.Model):
_name = "member.state.change"
member_id = fields.Many2one(
comodel_name='res.partner',
ondelete='cascade',
index=True
)
state = fields.Char(
'state',
size=15
)
......@@ -2,6 +2,9 @@
from openerp import _, api, models, fields
import datetime
import logging
_logger = logging.getLogger(__name__)
TARGET_STATUS_SELECTION = [
('unsubscribed', 'Unsubscribed'),
......@@ -26,7 +29,7 @@ class ResPartner(models.Model):
for p in self.env['res.partner']\
.search([('target_status', '!=', "")]):
new_values = {'target_status': "", "date_alert_stop": ""}
new_values = {'target_status': "", "date_alert_stop": False}
if p.final_ftop_point < 0:
new_values['cooperative_state'] = p.target_status
if new_values['cooperative_state'] == "unsubscribed":
......@@ -56,3 +59,60 @@ class ResPartner(models.Model):
today = datetime.datetime.now().strftime("%Y-%m-%d")
for ext in extension_model.search([('id', 'in', extension_ids)]):
ext.update({'date_stop': today})
@api.multi
def can_have_extension(self):
"""Return if the member can ask for an extension"""
answer = True
conf = self.env['ir.config_parameter']
max_nb = int(conf.get_param("lacagette_membership.max_successive_extensions"))
if max_nb == 1:
args = [('member_id', '=', self.id)]
states = self.env['member.state.change']\
.search(args, order='write_date DESC', limit=2)
"""
member.state.change may have no record for the current member
"""
if len(states) > 0:
if (len(states) == 1 and states[0]['state'] == 'delay'
or
len(states) == 2 and states[1]['state'] == 'delay'):
answer = False
else:
# need to load data
member = self.env['res.partner'].search([('id', '=', self.id)])[0]
# should exist an other way to do it , but haven't found it
if member.cooperative_state != "up_to_date":
answer = False
else:
# TODO : Must have a look to previous extensions
pass
return answer
def _write_state_change(self, state):
data = {'member_id': self.id, 'state': state}
self.env['member.state.change'].create(data)
@api.model
def update(self, vals):
res = super(ResPartner, self).write(vals)
#_logger.info("valeurs reçues pour update partner = %s", str(vals))
state_to_record = ""
if 'cooperative_state' in vals:
state_to_record = vals['cooperative_state']
elif 'current_cooperative_state' in vals:
state_to_record = vals['current_cooperative_state']
if len(state_to_record) > 0:
self._write_state_change(state_to_record)
return res
@api.model
def write(self, vals):
res = super(ResPartner, self).write(vals)
# _logger.info("valeurs reçues pour write partner = %s", str(vals))
if 'cooperative_state' in vals:
self._write_state_change(vals['cooperative_state'])
return res
\ No newline at end of file
......@@ -11,29 +11,34 @@ class ShiftCounterEvent(models.Model):
def _update_partner_target_status(self, vals):
"""actions if point_qty is negative"""
conf = self.env['ir.config_parameter']
suspension_limit = int(conf.get_param("lacagette_membership.points_limit_to_get_suspended"))
unsubscribe_limit = int(conf.get_param("lacagette_membership.points_limit_to_get_unsubscribed"))
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:
if points_after_removal <= suspension_limit or points_after_removal <= unsubscribe_limit:
if points_after_removal <= suspension_limit:
target_status = 'suspended'
if points_after_removal <= unsubscribe_limit:
target_status = 'unsubscribed'
res_partner[0].update({'target_status': target_status})
res_partner[0].update({'target_status': target_status,
'current_cooperative_state': res_partner[0].cooperative_state})
@api.model
def write(self, vals):
res = super(ShiftCounterEvent, self).write(vals)
#_logger.info("Vals reçues = %s", str(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))
_logger.info("Vals reçues creation = %s", str(vals))
return super(ShiftCounterEvent, self).create(vals)
\ No newline at end of file
......@@ -20,10 +20,11 @@ class ShiftRegistration(models.Model):
@api.multi
def write(self, vals):
res = super(ShiftRegistration, self).write(vals)
if 'state' in vals and vals['state'] == 'excused':
conf = self.env['ir.config_parameter']
absence_status = conf.get_param("lacagette_membership.absence_status")
if 'state' in vals and vals['state'] == absence_status:
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']\
.search([('id', 'in', self.ids)]):
......
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
,,,,,,,
,,,,,,,
access_model_member_state_change,access_model_member_state_change,model_member_state_change,coop_shift.group_shift_user,1,1,1,1
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