2014-12-02 12:55:12 +01: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.
|
2016-06-03 00:00:01 +02:00
|
|
|
from trytond.model import ModelSQL, ModelView, fields, dualmethod
|
2012-09-24 22:17:50 +02:00
|
|
|
from trytond.pool import Pool, PoolMeta
|
2012-09-21 15:20:25 +02:00
|
|
|
from trytond.transaction import Transaction
|
2011-07-03 13:18:53 +02:00
|
|
|
|
2008-09-18 16:20:13 +02:00
|
|
|
|
2012-09-24 22:17:50 +02:00
|
|
|
__all__ = ['Cron', 'CronCompany']
|
|
|
|
|
|
|
|
|
|
|
2018-06-26 19:11:46 +02:00
|
|
|
class Cron(metaclass=PoolMeta):
|
2012-09-24 22:17:50 +02:00
|
|
|
__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
|
|
|
|
2016-06-03 00:00:01 +02:00
|
|
|
@dualmethod
|
|
|
|
|
@ModelView.button
|
|
|
|
|
def run_once(cls, crons):
|
|
|
|
|
for cron in crons:
|
|
|
|
|
if not cron.companies:
|
|
|
|
|
super(Cron, cls).run_once([cron])
|
|
|
|
|
else:
|
|
|
|
|
for company in cron.companies:
|
|
|
|
|
with Transaction().set_context(company=company.id):
|
|
|
|
|
super(Cron, cls).run_once([cron])
|
2008-09-18 17:07:35 +02:00
|
|
|
|
2012-09-24 22:17:50 +02:00
|
|
|
@staticmethod
|
|
|
|
|
def default_companies():
|
|
|
|
|
Company = Pool().get('company.company')
|
2018-06-26 19:11:46 +02:00
|
|
|
return list(map(int, Company.search([])))
|
2009-03-05 14:52:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class CronCompany(ModelSQL):
|
|
|
|
|
'Cron - Company'
|
2012-09-24 22:17:50 +02:00
|
|
|
__name__ = 'ir.cron-company.company'
|
2009-03-05 14:52:48 +01:00
|
|
|
_table = 'cron_company_rel'
|
|
|
|
|
cron = fields.Many2One('ir.cron', 'Cron', ondelete='CASCADE',
|
2012-03-05 10:53:01 +01:00
|
|
|
required=True, select=True)
|
2009-03-05 14:52:48 +01:00
|
|
|
company = fields.Many2One('company.company', 'Company', ondelete='CASCADE',
|
2012-03-05 10:53:01 +01:00
|
|
|
required=True, select=True)
|