Commit 18714da9 by François C.

Ajout cron fin extension si à jour

parent 866532a2
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
# #
'category': 'Uncategorized', 'category': 'Uncategorized',
'version': '0.0.2', 'version': '0.0.3',
# any module necessary for this one to work correctly # any module necessary for this one to work correctly
'depends': ['base', 'coop_shift'], 'depends': ['base', 'coop_shift'],
......
...@@ -5,16 +5,15 @@ ...@@ -5,16 +5,15 @@
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
--> -->
<odoo> <odoo>
<record forcecreate="True" id="cron_ending_abcd_shift_preiod" model="ir.cron"> <record forcecreate="True" id="cron_close_unnecessary_extensions" model="ir.cron">
<field name="name">Ending ABCD shift period</field> <field name="name">Close unnecessary Extensions</field>
<field name="user_id" ref="base.user_root" /> <field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field> <field name="interval_number">1</field>
<field name="interval_type">days</field> <field name="interval_type">days</field>
<field name="numbercall">-1</field> <field name="numbercall">-1</field>
<field name="nextcall" eval="(DateTime.now() + timedelta(days=1)).strftime('%Y-%m-%d 20:00:00')"/> <field name="doall" eval="True"/>
<field name="doall" eval="False"/> <field name="model" eval="'res.partner'"/>
<field name="model" eval="'shift.registration'"/> <field name="function" eval="'run_close_unnecessary_opened_extensions'"/>
<field name="function" eval="'send_shift_missing_emails'"/>
<field name="args" eval="'()'"/> <field name="args" eval="'()'"/>
<field name="active" eval="False"/> <field name="active" eval="False"/>
<field name="priority">2</field> <field name="priority">2</field>
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from openerp import _, api, models, fields from openerp import _, api, models, fields
import datetime
class ResPartner(models.Model): class ResPartner(models.Model):
_inherit = 'res.partner' _inherit = 'res.partner'
...@@ -10,4 +11,21 @@ class ResPartner(models.Model): ...@@ -10,4 +11,21 @@ class ResPartner(models.Model):
"Number of make-ups to done", "Number of make-ups to done",
default= 0) default= 0)
\ No newline at end of file #@api.onchange('cooperativestate') : could be used only if it is called from client
@api.model
def run_close_unnecessary_opened_extensions(self):
"""Method called by cron task"""
sql = """
SELECT s.id
FROM shift_extension as s
WHERE s.date_stop > now()
AND partner_id IN (SELECT id FROM res_partner WHERE cooperative_state='up_to_date')
"""
self.env.cr.execute(sql)
extension_ids = self.env.cr.fetchall()
if len(extension_ids) > 0:
extension_model = self.env['shift.extension']
today = datetime.datetime.now().strftime("%Y-%m-%d")
for ext in extension_model.search([('id', 'in', extension_ids)]):
ext.update({'date_stop': today})
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