Files
tryton/cron.py
T

37 lines
1.5 KiB
Python
Raw Normal View History

2008-09-18 16:20:13 +02:00
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
2009-02-28 16:59:20 +01:00
from trytond.model import ModelView, ModelSQL, fields
2008-09-18 16:20:13 +02:00
2009-02-28 16:59:20 +01:00
class Cron(ModelSQL, ModelView):
2008-09-18 16:20:13 +02:00
"Cron"
_name = "ir.cron"
2009-03-05 14:52:48 +01:00
companies = fields.Many2Many('ir.cron-company.company', 'cron', 'company',
'Companies', help='Companies registered for this cron')
2008-09-18 16:20:13 +02:00
2008-10-22 15:49:48 +02:00
def _callback(self, cursor, cron):
cursor.execute("SELECT company from cron_company_rel "
"WHERE cron = %s", (cron['id'],))
2008-11-06 14:55:54 +01:00
for company, in cursor.fetchall():
cursor.execute("UPDATE res_user SET company = %s, main_company = %s "
2008-10-22 15:49:48 +02:00
"WHERE id = %s", (company, company, cron['user']))
super(Cron, self)._callback(cursor, cron)
cursor.execute("UPDATE res_user SET company = NULL, main_company = NULL "
2008-10-22 15:49:48 +02:00
"WHERE id = %s", (cron['user'],))
2008-09-30 00:01:39 +02:00
def default_companies(self, cursor, user, context=None):
company_obj = self.pool.get('company.company')
return company_obj.search(cursor, user, [], context=context)
2008-09-18 16:20:13 +02:00
Cron()
2009-03-05 14:52:48 +01:00
class CronCompany(ModelSQL):
'Cron - Company'
_name = 'ir.cron-company.company'
_table = 'cron_company_rel'
cron = fields.Many2One('ir.cron', 'Cron', ondelete='CASCADE',
required=True, select=1)
company = fields.Many2One('company.company', 'Company', ondelete='CASCADE',
required=True, select=1)
CronCompany()