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 @@ ...@@ -16,7 +16,7 @@
# #
'category': 'Uncategorized', 'category': 'Uncategorized',
'version': '0.0.7.4', 'version': '0.0.7.5',
# any module necessary for this one to work correctly # any module necessary for this one to work correctly
'depends': ['base', 'coop_membership', 'coop_shift'], 'depends': ['base', 'coop_membership', 'coop_shift'],
......
...@@ -7,4 +7,5 @@ from . import shift_shift ...@@ -7,4 +7,5 @@ from . import shift_shift
from . import member_state_change from . import member_state_change
from . import shift_template from . import shift_template
from . import shift_template_registration_line from . import shift_template_registration_line
from . import shift_template_registration
from . import shift_extension
...@@ -37,7 +37,8 @@ WORKING_STATE_SELECTION = [ ...@@ -37,7 +37,8 @@ WORKING_STATE_SELECTION = [
('delay', 'Delay'), ('delay', 'Delay'),
('blocked', 'Blocked'), ('blocked', 'Blocked'),
('gone', 'Gone'), ('gone', 'Gone'),
('associated', 'Associated') ('associated', 'Associated'),
('unsubscribed', 'Unsubscribed')
] ]
class ResPartner(models.Model): class ResPartner(models.Model):
...@@ -45,9 +46,14 @@ class ResPartner(models.Model): ...@@ -45,9 +46,14 @@ class ResPartner(models.Model):
# Columns Section # Columns Section
makeups_to_do = fields.Integer( makeups_to_do = fields.Integer(
"Number of make-ups to done", "Number of make-ups to do",
default= 0) 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( target_status = fields.Selection(
selection=TARGET_STATUS_SELECTION, default='') selection=TARGET_STATUS_SELECTION, default='')
...@@ -57,7 +63,6 @@ class ResPartner(models.Model): ...@@ -57,7 +63,6 @@ class ResPartner(models.Model):
compute='_compute_lacagette_cooperative_state' compute='_compute_lacagette_cooperative_state'
) )
working_state = fields.Selection( working_state = fields.Selection(
selection=WORKING_STATE_SELECTION, string='Working State', store=True, selection=WORKING_STATE_SELECTION, string='Working State', store=True,
compute='_compute_lacagette_working_state', help="This state depends on the" compute='_compute_lacagette_working_state', help="This state depends on the"
...@@ -68,55 +73,95 @@ class ResPartner(models.Model): ...@@ -68,55 +73,95 @@ class ResPartner(models.Model):
extra_shift_done = fields.Integer( extra_shift_done = fields.Integer(
"Number of shift done with both of the associate", "Number of shift done with both of the associate",
default= 0) default= 0)
@api.multi @api.multi
def _compute_lacagette_working_state(self): def _compute_lacagette_working_state(self):
_logger.debug("Dans _compute_lacagette_working_state") _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: for partner in self:
_logger.debug("partner_id = %s, cooperative_state = %s", str(partner.id), str(partner.cooperative_state)) _logger.debug("partner_id = %s, cooperative_state = %s", str(partner.id), str(partner.cooperative_state))
if partner.is_associated_people is True: state = 'up_to_date'
partner.working_state = partner.parent_id.cooperative_state if partner.leave_ids:
else: is_exempted = partner.leave_ids.filtered(
if partner.cooperative_state in ['gone', 'associated']: lambda l: l.state == 'done' and l.start_date <= current_datetime and l.stop_date >=
partner.working_state = partner.cooperative_state 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: else:
potential_associated_record = self.env['res.partner'].search([('email','=',self.email), ('is_associated_people', '=', True)]) if partner.cooperative_state in ['gone', 'associated']:
if potential_associated_record: state = partner.cooperative_state
partner.working_state = 'associated' else:
potential_associated_record = self.env['res.partner'].search([('email','=',self.email), ('is_associated_people', '=', True)])
# Not sure, it is useful, but _compute_working_state is overriden, calling our own method 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 @api.multi
def _compute_working_state(self): def _compute_working_state(self):
self._compute_lacagette_working_state() 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 @api.multi
def _compute_lacagette_cooperative_state(self): def _compute_lacagette_cooperative_state(self):
_logger.debug("Dans _compute_lacagette_cooperative_state") _logger.debug("Dans _compute_lacagette_cooperative_state")
for partner in self: for partner in self:
# _logger.debug("Partner = %s", str(partner.read())) # _logger.debug("Partner = %s", str(partner.read()))
_logger.debug("partner_id = %s, working_state = %s", str(partner.id), str(partner.working_state)) _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: state = 'up_to_date'
partner.cooperative_state = 'not_concerned' if partner.is_member is False and partner.is_associated_people is False:
state= 'not_concerned'
else: else:
if partner.is_associated_people: if partner.is_associated_people:
# Associated People # Associated People
partner.cooperative_state = partner.parent_id.cooperative_state state = partner.parent_id.cooperative_state
elif partner.is_worker_member: elif partner.is_member:
# Type A Subscriptor # Type A Subscriptor
if partner.is_unsubscribed and partner.working_state not in ['gone', 'associated']: if partner.is_unsubscribed and partner.working_state not in ['gone', 'associated']:
partner.cooperative_state = 'unsubscribed' state = 'unsubscribed'
elif partner.is_unpayed: elif partner.is_unpayed:
partner.cooperative_state = 'unpayed' state = 'unpayed'
elif partner.working_state:
state = partner.working_state
else: 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( @api.depends(
'working_state', 'is_unpayed', 'is_unsubscribed', 'working_state', 'is_unpayed', 'is_unsubscribed',
'is_worker_member', 'is_associated_people', 'is_worker_member', 'is_associated_people',
...@@ -252,9 +297,15 @@ class ResPartner(models.Model): ...@@ -252,9 +297,15 @@ class ResPartner(models.Model):
def set_special_state(self, cr, uid, partner, context=None): def set_special_state(self, cr, uid, partner, context=None):
new_state = partner['state']
if partner['state'] == 'cancel_special': if partner['state'] == 'cancel_special':
partner['state'] = 'unsubscribed' new_state = 'unsubscribed'
return self.write(cr, uid, [partner['id']], {'cooperative_state': partner['state'], 'working_state': partner['state']} , context=context) 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): def _write_state_change(self, state):
data = {'member_id': self.id, 'state': state} data = {'member_id': self.id, 'state': state}
...@@ -281,6 +332,9 @@ class ResPartner(models.Model): ...@@ -281,6 +332,9 @@ class ResPartner(models.Model):
_logger.info("valeurs recues pour write partner = %s", str(vals)) _logger.info("valeurs recues pour write partner = %s", str(vals))
if 'cooperative_state' in vals: if 'cooperative_state' in vals:
self._write_state_change(vals['cooperative_state']) 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) 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): ...@@ -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) # Missing a makeup leads to have an additional makeup (the shift you initialy missed + the makeup you missed)
if s.is_makeup is True: if s.is_makeup is True:
to_add += 1 to_add += 1
new_makeups_to_do = s.partner_id.makeups_to_do + to_add s.partner_id.update({'makeups_to_add': to_add})
s.partner_id.update({'makeups_to_do': new_makeups_to_do}) return super(ShiftRegistration, self).write(vals)
return super(ShiftRegistration, self).write(vals)
\ No newline at end of file
# -*- 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): ...@@ -33,4 +33,6 @@ class ShiftTemplateRegistrationLine(models.Model):
coop_state = 'unsubscribed' coop_state = 'unsubscribed'
member.update({'cooperative_state': coop_state}) member.update({'cooperative_state': coop_state})
_logger.info("new cooperative_state = %s for %s", coop_state, str(member.id)) _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 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