Commit a3e3560c by François C.

Merge branch '6833--nouveaux-sans-statut' into 'dev_cooperatic'

Rectifications nécessaires suite prise de contrôle des changements de statuts par module lacagette_membership

See merge request !79
parents 13c541f0 f4187284
......@@ -16,7 +16,7 @@
#
'category': 'Uncategorized',
'version': '0.0.7.4',
'version': '0.0.7.5',
# any module necessary for this one to work correctly
'depends': ['base', 'coop_membership', 'coop_shift'],
......
......@@ -7,4 +7,5 @@ from . import shift_shift
from . import member_state_change
from . import shift_template
from . import shift_template_registration_line
from . import shift_template_registration
from . import shift_extension
......@@ -37,7 +37,8 @@ WORKING_STATE_SELECTION = [
('delay', 'Delay'),
('blocked', 'Blocked'),
('gone', 'Gone'),
('associated', 'Associated')
('associated', 'Associated'),
('unsubscribed', 'Unsubscribed')
]
class ResPartner(models.Model):
......@@ -45,9 +46,14 @@ class ResPartner(models.Model):
# Columns Section
makeups_to_do = fields.Integer(
"Number of make-ups to done",
"Number of make-ups to do",
default= 0)
makeups_to_add = fields.Integer(
"Number of make-ups to add (set by shift_registration)",
default= 0)
# To be removed
target_status = fields.Selection(
selection=TARGET_STATUS_SELECTION, default='')
......@@ -57,7 +63,6 @@ class ResPartner(models.Model):
compute='_compute_lacagette_cooperative_state'
)
working_state = fields.Selection(
selection=WORKING_STATE_SELECTION, string='Working State', store=True,
compute='_compute_lacagette_working_state', help="This state depends on the"
......@@ -68,55 +73,95 @@ class ResPartner(models.Model):
extra_shift_done = fields.Integer(
"Number of shift done with both of the associate",
default= 0)
@api.multi
def _compute_lacagette_working_state(self):
_logger.debug("Dans _compute_lacagette_working_state")
conf = self.env['ir.config_parameter']
unsubscribe_limit = int(conf.get_param("lacagette_membership.points_limit_to_get_unsubscribed"))
current_datetime = fields.Datetime.now()
for partner in self:
_logger.debug("partner_id = %s, cooperative_state = %s", str(partner.id), str(partner.cooperative_state))
if partner.is_associated_people is True:
partner.working_state = partner.parent_id.cooperative_state
else:
if partner.cooperative_state in ['gone', 'associated']:
partner.working_state = partner.cooperative_state
state = 'up_to_date'
if partner.leave_ids:
is_exempted = partner.leave_ids.filtered(
lambda l: l.state == 'done' and l.start_date <= current_datetime and l.stop_date >=
current_datetime and l.partner_state == 'exempted')
# _logger.debug("is_exempted = %s", str(is_exempted))
if is_exempted:
_logger.debug("On met le statut exempté")
state = 'exempted'
if state != 'exempted':
if partner.is_associated_people is True:
state = partner.parent_id.cooperative_state
else:
potential_associated_record = self.env['res.partner'].search([('email','=',self.email), ('is_associated_people', '=', True)])
if potential_associated_record:
partner.working_state = 'associated'
# Not sure, it is useful, but _compute_working_state is overriden, calling our own method
if partner.cooperative_state in ['gone', 'associated']:
state = partner.cooperative_state
else:
potential_associated_record = self.env['res.partner'].search([('email','=',self.email), ('is_associated_people', '=', True)])
if potential_associated_record:
state = 'associated'
else:
if partner.is_unsubscribed is False:
points = 0
if partner.shift_type == 'standard':
points = partner.final_standard_point
else:
points = partner.final_ftop_point
if points < 0:
if points <= unsubscribe_limit:
state = 'unsubscribed'
self.env['shift.counter.event'].unsubscribe_partner(partner, unsubscribe_limit, points)
else:
if partner.date_alert_stop:
if partner.date_delay_stop > current_datetime:
state = 'delay'
else:
state = 'suspended'
else:
state = 'suspended'
else:
state = 'unsubscribed'
partner.working_state = state
# Overriding by calling our own method (which is mentionned in field declaration)
@api.depends('is_blocked', 'final_standard_point', 'final_ftop_point', 'shift_type', 'date_alert_stop', 'date_delay_stop', 'leave_ids.state')
@api.multi
def _compute_working_state(self):
self._compute_lacagette_working_state()
@api.depends(
'working_state', 'is_unpayed', 'is_unsubscribed',
'is_worker_member', 'is_associated_people',
'parent_id.cooperative_state')
@api.multi
def _compute_lacagette_cooperative_state(self):
_logger.debug("Dans _compute_lacagette_cooperative_state")
for partner in self:
# _logger.debug("Partner = %s", str(partner.read()))
_logger.debug("partner_id = %s, working_state = %s", str(partner.id), str(partner.working_state))
if partner.is_member is False and partner.is_associated_people is False and partner.is_worker_member is False:
partner.cooperative_state = 'not_concerned'
state = 'up_to_date'
if partner.is_member is False and partner.is_associated_people is False:
state= 'not_concerned'
else:
if partner.is_associated_people:
# Associated People
partner.cooperative_state = partner.parent_id.cooperative_state
elif partner.is_worker_member:
state = partner.parent_id.cooperative_state
elif partner.is_member:
# Type A Subscriptor
if partner.is_unsubscribed and partner.working_state not in ['gone', 'associated']:
partner.cooperative_state = 'unsubscribed'
state = 'unsubscribed'
elif partner.is_unpayed:
partner.cooperative_state = 'unpayed'
state = 'unpayed'
elif partner.working_state:
state = partner.working_state
else:
partner.cooperative_state = partner.working_state
partner.working_state = state
partner.cooperative_state = state
_logger.debug("A l'issue du traitement partner_id = %s, working_state = %s, cooperative_state = %s", str(partner.id), str(partner.working_state), str(partner.cooperative_state))
# Not sure, it is useful, but _compute_cooperative_state is overriden, calling our own method
# Overriding by calling our own method (which is mentionned in field declaration)
@api.depends(
'working_state', 'is_unpayed', 'is_unsubscribed',
'is_worker_member', 'is_associated_people',
......@@ -252,9 +297,15 @@ class ResPartner(models.Model):
def set_special_state(self, cr, uid, partner, context=None):
new_state = partner['state']
if partner['state'] == 'cancel_special':
partner['state'] = 'unsubscribed'
return self.write(cr, uid, [partner['id']], {'cooperative_state': partner['state'], 'working_state': partner['state']} , context=context)
new_state = 'unsubscribed'
write_result = self.write(cr, uid, [partner['id']], {'cooperative_state': new_state, 'working_state': new_state} , context=context)
if new_state == 'unsubscribed':
member = self.pool.get('res.partner').browse(cr, uid, partner['id'], context)
return member.recompute_member_states()
else:
return write_result
def _write_state_change(self, state):
data = {'member_id': self.id, 'state': state}
......@@ -281,6 +332,9 @@ class ResPartner(models.Model):
_logger.info("valeurs recues pour write partner = %s", str(vals))
if 'cooperative_state' in vals:
self._write_state_change(vals['cooperative_state'])
if 'barcode_base' in vals:
vals['cooperative_state'] = 'unsubscribed'
vals['working_state'] = 'unsubscribed'
return super(ResPartner, self).write(vals)
......
# -*- coding: utf-8 -*-
from openerp import _, api, models, fields
import logging
import datetime
_logger = logging.getLogger(__name__)
class ShiftExtension(models.Model):
_inherit = 'shift.extension'
@api.model
def _update_member_status(self, vals):
res_partner = self.env['res.partner'].search([('id', '=', vals['partner_id'])])
if res_partner:
res_partner[0].recompute_member_states()
@api.model
def write(self, vals):
_logger.debug("Shift extension Vals recues = %s", str(vals))
res = super(ShiftExtension, self).write(vals)
self._update_member_status(vals)
return res
@api.model
def create(self, vals):
_logger.debug("Shift extension Vals recues creation = %s", str(vals))
res = super(ShiftExtension, self).create(vals)
self._update_member_status(vals)
return res
......@@ -41,6 +41,5 @@ class ShiftRegistration(models.Model):
# Missing a makeup leads to have an additional makeup (the shift you initialy missed + the makeup you missed)
if s.is_makeup is True:
to_add += 1
new_makeups_to_do = s.partner_id.makeups_to_do + to_add
s.partner_id.update({'makeups_to_do': new_makeups_to_do})
return super(ShiftRegistration, self).write(vals)
\ No newline at end of file
s.partner_id.update({'makeups_to_add': to_add})
return super(ShiftRegistration, self).write(vals)
# -*- coding: utf-8 -*-
from openerp import api, models
import logging
_logger = logging.getLogger(__name__)
class ShiftTemplateRegistration(models.Model):
_inherit = 'shift.template.registration'
@api.model
def create(self, vals):
super_res = super(ShiftTemplateRegistration, self.with_context(
dict(self.env.context, **{'creation_in_progress': True}))).create(vals)
if 'partner_id' in vals:
member = self.env['res.partner'].search([('id', '=', vals['partner_id'])])
member.recompute_member_states()
return super_res
......@@ -33,4 +33,6 @@ class ShiftTemplateRegistrationLine(models.Model):
coop_state = 'unsubscribed'
member.update({'cooperative_state': coop_state})
_logger.info("new cooperative_state = %s for %s", coop_state, str(member.id))
_logger.info("On va recalculer le statut du membre = %s", str(member.id))
member.recompute_member_states()
return super_res
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