[IMP] event: add a cron that clean the event pipeline

The cron will move every ended events in the next "ended stage"
We inherit from `ir.autovacuum`, so the method `power_on` is called one time per day.

Task #2088538
This commit is contained in:
Debauche Stéphane
2020-01-08 09:11:51 +00:00
committed by Thibault Delavallée
parent bd61b6cd38
commit a321963d19
2 changed files with 22 additions and 0 deletions
+1
View File
@@ -6,3 +6,4 @@ from . import event_mail
from . import event_stage
from . import res_config_settings
from . import res_partner
from . import ir_autovacuum
+21
View File
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models, fields
class AutoVacuum(models.AbstractModel):
_inherit = 'ir.autovacuum'
@api.model
def power_on(self, *args, **kwargs):
"""
Cron which drags all events which end date is < now (= passed)
into the first next (by sequence) stage defined as "Ended"
(if they are not already in an ended stage)
"""
ended_events = self.env['event.event'].search([('date_end', '<', fields.Datetime.now()), ('stage_id.pipe_end', '=', False)])
if ended_events:
ended_events.action_set_done()
return super(AutoVacuum, self).power_on(*args, **kwargs)