Commit e1c5eb54 by Odoo

Ajustements pour cron recompute members working and cooperative states

parent e9df4002
......@@ -557,6 +557,7 @@ class Channel(object):
:return: iterator of :py:class:`connector.jobrunner.ChannelJob`
"""
# enqueue jobs of children channels
for child in self.children.values():
for job in child.get_jobs_to_run(now):
......
......@@ -11,12 +11,12 @@
""",
'author': "fracolo/cooperatic",
'author': "fracolo/cooperatic/coopdev",
'website': "https://lacagette-coop.fr",
#
'category': 'Uncategorized',
'version': '0.0.7.2',
'version': '0.0.7.3',
# any module necessary for this one to work correctly
'depends': ['base', 'coop_membership', 'coop_shift'],
......
......@@ -57,4 +57,17 @@
<field name="active" eval="False"/>
<field name="priority">1</field>
</record>
</odoo>
\ No newline at end of file
<record forcecreate="True" id="cron_recompute_working_and_cooperative_states" model="ir.cron">
<field name="name">Partner: Recompute cooperative and working states (La Cagette)</field>
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="model" eval="'res.partner'"/>
<field name="function" eval="'run_recompute_member_states'"/>
<field name="args" eval="'()'"/>
<field name="active" eval="False"/>
<field name="priority">1</field>
</record>
</odoo>
......@@ -7,3 +7,4 @@ from . import shift_shift
from . import member_state_change
from . import shift_template
from . import shift_template_registration_line
# -*- coding: utf-8 -*-
from openerp import _, api, models, fields
from openerp.addons.connector.session import ConnectorSession
from openerp.addons.connector.queue.job import job
import datetime
import logging
......@@ -56,6 +58,28 @@ class ResPartner(models.Model):
if potential_associated_record:
partner.working_state = 'associated'
@api.depends(
'working_state', 'is_unpayed', 'is_unsubscribed',
'is_worker_member', 'is_associated_people',
'parent_id.cooperative_state')
@api.multi
def _compute_cooperative_state(self):
for partner in self:
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'
else:
if partner.is_associated_people:
# Associated People
partner.cooperative_state = partner.parent_id.cooperative_state
elif partner.is_worker_member:
# Type A Subscriptor
if partner.is_unsubscribed and partner.working_state not in ['gone', 'associated']:
partner.cooperative_state = 'unsubscribed'
elif partner.is_unpayed:
partner.cooperative_state = 'unpayed'
else:
partner.cooperative_state = partner.working_state
@api.multi
def recompute_member_states(self):
for record in self:
......@@ -213,3 +237,11 @@ class ResPartner(models.Model):
self._write_state_change(vals['cooperative_state'])
return super(ResPartner, self).write(vals)
@api.model
def run_recompute_member_states(self):
# Function Called by the CRON
filters = [('is_member', '=', True),
('active', '=', True)]
partners = self.search(filters)
partners.recompute_member_states()
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