Commit d28f4b0d by Odoo

WIP: les fonctions de recalcul des statuts sont exclusivement celles définies…

WIP: les fonctions de recalcul des statuts sont exclusivement celles définies dans lacagette_membership
parent cac9391a
......@@ -16,7 +16,7 @@
#
'category': 'Uncategorized',
'version': '0.0.6',
'version': '0.0.7',
# any module necessary for this one to work correctly
'depends': ['base', 'coop_membership', 'coop_shift'],
......
# -*- coding: utf-8 -*-
from openerp import _, api, models, fields
from openerp.addons.coop_membership.models.res_partner import ResPartner as LouveResPartner
import datetime
import logging
......@@ -26,7 +27,21 @@ EXTRA_COOPERATIVE_STATE_SELECTION = [
('associated', 'Associated')
]
class ResPartner(models.Model):
WORKING_STATE_SELECTION = [
('exempted', 'Exempted'),
('vacation', 'On Vacation'),
('up_to_date', 'Up to date'),
('alert', 'Alert'),
('suspended', 'Suspended'),
('delay', 'Delay'),
('blocked', 'Blocked'),
('gone', 'Gone'),
('associated', 'Associated')
]
class CagetteResPartner(models.Model):
_inherit = 'res.partner'
# Columns Section
......@@ -38,12 +53,69 @@ class ResPartner(models.Model):
selection=TARGET_STATUS_SELECTION, default='')
cooperative_state = fields.Selection(
selection=EXTRA_COOPERATIVE_STATE_SELECTION, default='not_concerned')
selection=EXTRA_COOPERATIVE_STATE_SELECTION, default='not_concerned',
store=True, compute='_compute_cooperative_state')
working_state = fields.Selection(
selection=WORKING_STATE_SELECTION, string='Working State', store=True,
compute='_compute_working_state', help="This state depends on the"
" shifts realized by the partner.")
extra_shift_done = fields.Integer(
"Number of shift done with both of the associate",
default= 0)
@api.depends('working_state')
@api.multi
def _compute_cooperative_state(self):
for partner in self:
if partner.cooperative_state not in ['associated', 'gone']:
partner.cooperative_state = partner.working_state
@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):
"""This function should be called in a daily CRON"""
current_datetime = fields.Datetime.now()
for partner in self:
state = 'up_to_date'
if partner.is_blocked:
state = 'blocked'
elif partner.is_vacation:
state = 'vacation'
else:
point = 0
if partner.in_ftop_team:
point = partner.final_ftop_point
else:
point = partner.final_standard_point
if point < 0:
if partner.date_alert_stop:
if partner.date_delay_stop > current_datetime:
# There is Delay
state = 'delay'
# elif partner.date_alert_stop > current_datetime:
# Grace State
# state = 'alert'
else:
state = 'suspended'
else:
state = 'suspended'
elif partner.is_exempted:
state = 'exempted'
# Change the status from Up to Date
# to Alert if standard_counter < 0
if state == 'up_to_date' and partner.final_standard_point < 0:
state = 'alert'
if partner.working_state != state:
partner.working_state = state
@api.model
def run_process_target_status(self):
"""Method called by cron task"""
......@@ -185,7 +257,7 @@ class ResPartner(models.Model):
if len(state_to_record) > 0:
self._write_state_change(state_to_record)
return super(ResPartner, self).update(vals)
return super(CagetteResPartner, self).update(vals)
@api.multi
......@@ -193,5 +265,8 @@ 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'])
return super(ResPartner, self).write(vals)
return super(CagetteResPartner, self).write(vals)
# Needed to ensure working_state and cooperative_state to be only handled by LaCagette rules
LouveResPartner._compute_cooperative_state = CagetteResPartner._compute_cooperative_state
LouveResPartner._compute_working_state = CagetteResPartner._compute_working_state
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