Files
tryton/cron.py
T
Bertrand Chenal e65d156693 Improvement when looping on companies for cron:
* update both company and main_company feilds
* reset those fields at the end.
2008-09-18 17:07:35 +02:00

23 lines
1001 B
Python

#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
from trytond.osv import fields, OSV
class Cron(OSV):
"Cron"
_name = "ir.cron"
companies = fields.Many2Many(
'company.company', 'cron_company_rel', 'cron', 'company', 'Companies',
help='Companies registered for this cron')
def _callback(self, cursor, user, job_id, model, func, args):
cursor.execute("SELECT company,cron from cron_company_rel "
"WHERE cron = %s", (job_id,))
for company, cron in cursor.fetchall():
cursor.execute("UPDATE res_user SET company = %s, main_company = %s "
"WHERE id = %s", (company, company, user))
super(Cron, self)._callback(cursor, user, job_id, model, func, args)
cursor.execute("UPDATE res_user SET company = NULL, main_company = NULL "
"WHERE id = %s", (user,))
Cron()