forked from NaN-tic/trytond-activity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration.py
69 lines (58 loc) · 2.45 KB
/
configuration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from trytond import backend
from trytond.model import ModelSingleton, ModelSQL, ModelView, fields
from trytond.pool import Pool
from trytond.pyson import Eval, Id
from trytond.modules.company.model import (
CompanyMultiValueMixin, CompanyValueMixin)
__all__ = ['Configuration', 'ConfigurationSequence']
class Configuration(
ModelSingleton, ModelSQL, ModelView, CompanyMultiValueMixin):
'Activity Configuration'
__name__ = 'activity.configuration'
activity_sequence = fields.MultiValue(fields.Many2One('ir.sequence',
'Activity Sequence', required=True,
domain=[
('company', 'in',
[Eval('context', {}).get('company', -1), None]),
('sequence_type', '=', Id('activity', 'sequence_type_activity')),
]))
@classmethod
def multivalue_model(cls, field):
pool = Pool()
if field == 'activity_sequence':
return pool.get('activity.configuration.sequence')
return super(Configuration, cls).multivalue_model(field)
@classmethod
def default_activity_sequence(cls, **pattern):
field_name = 'activity_sequence'
return getattr(
cls.multivalue_model(field_name),
'default_%s' % field_name, lambda: None)()
class ConfigurationSequence(ModelSQL, CompanyValueMixin):
'Activity Sequence Configuration'
__name__ = 'activity.configuration.sequence'
activity_sequence = fields.Many2One('ir.sequence',
'Activity Sequence', required=True,
domain=[
('company', 'in', [Eval('company', -1), None]),
('sequence_type', '=', Id('activity', 'sequence_type_activity')),
],
depends=['company'])
@classmethod
def __register__(cls, module_name):
TableHandler = backend.TableHandler
old_table = 'activity_configuration_company'
if (not TableHandler.table_exist(cls._table)
and TableHandler.table_exist(old_table)):
TableHandler.table_rename(old_table, cls._table)
super(ConfigurationSequence, cls).__register__(module_name)
@classmethod
def default_activity_sequence(cls):
pool = Pool()
ModelData = pool.get('ir.model.data')
try:
return ModelData.get_id('activity', 'sequence_activity')
except KeyError:
return None