Files
tryton/modules/company/ir.py
T

125 lines
3.7 KiB
Python
Raw Normal View History

# 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.model import ModelSQL, ModelView, dualmethod, fields
2021-12-11 17:58:42 +01:00
from trytond.pool import Pool, PoolMeta
2022-10-09 13:27:55 +02:00
from trytond.tools import timezone as tz
from trytond.transaction import Transaction
class Sequence(metaclass=PoolMeta):
__name__ = 'ir.sequence'
2021-04-20 09:18:58 +02:00
company = fields.Many2One(
'company.company', "Company",
help="Restricts the sequence usage to the company.")
@classmethod
def __setup__(cls):
super(Sequence, cls).__setup__()
cls._order.insert(0, ('company', 'ASC'))
@staticmethod
def default_company():
return Transaction().context.get('company')
class SequenceStrict(Sequence):
__name__ = 'ir.sequence.strict'
class Date(metaclass=PoolMeta):
__name__ = 'ir.date'
@classmethod
def today(cls, timezone=None):
pool = Pool()
Company = pool.get('company.company')
company_id = Transaction().context.get('company')
if timezone is None and company_id:
company = Company(company_id)
2022-10-09 13:27:55 +02:00
if company.timezone:
timezone = tz.ZoneInfo(company.timezone)
return super(Date, cls).today(timezone=timezone)
class Rule(metaclass=PoolMeta):
__name__ = 'ir.rule'
2019-12-07 15:15:31 +01:00
@classmethod
def __setup__(cls):
super().__setup__()
cls.domain.help += (
2022-10-03 09:31:34 +02:00
'\n- "companies" as list of ids from the current user')
2019-12-07 15:15:31 +01:00
@classmethod
def _get_cache_key(cls, model_name):
pool = Pool()
User = pool.get('res.user')
key = super()._get_cache_key(model_name)
return (*key, User.get_companies())
2019-12-07 15:15:31 +01:00
@classmethod
def _get_context(cls, model_name):
2019-12-07 15:15:31 +01:00
pool = Pool()
User = pool.get('res.user')
context = super()._get_context(model_name)
context['companies'] = User.get_companies()
2019-12-07 15:15:31 +01:00
return context
class Cron(metaclass=PoolMeta):
__name__ = "ir.cron"
companies = fields.Many2Many('ir.cron-company.company', 'cron', 'company',
2019-12-18 09:16:46 +01:00
'Companies', help='Companies registered for this cron.')
@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])
@staticmethod
def default_companies():
Company = Pool().get('company.company')
return list(map(int, Company.search([])))
class CronCompany(ModelSQL):
'Cron - Company'
__name__ = 'ir.cron-company.company'
_table = 'cron_company_rel'
cron = fields.Many2One(
'ir.cron', "Cron", ondelete='CASCADE', required=True)
company = fields.Many2One(
'company.company', "Company", ondelete='CASCADE', required=True)
2020-09-17 17:18:02 +02:00
class EmailTemplate(metaclass=PoolMeta):
__name__ = 'ir.email.template'
@classmethod
def email_models(cls):
return super().email_models() + ['company.employee']
@classmethod
def _get_address(cls, record):
pool = Pool()
Employee = pool.get('company.employee')
address = super()._get_address(record)
if isinstance(record, Employee):
address = cls._get_address(record.party)
return address
@classmethod
def _get_language(cls, record):
pool = Pool()
Employee = pool.get('company.employee')
language = super()._get_language(record)
if isinstance(record, Employee):
language = cls._get_language(record.party)
return language