-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfiguration.py
68 lines (56 loc) · 2.28 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
#The COPYRIGHT file at the top level of this repository contains the full
#copyright notices and license terms.
from trytond.model import Model, ModelView, ModelSQL, ModelSingleton, fields
from trytond.pool import Pool
from trytond.transaction import Transaction
__all__ = ['Configuration', 'ConfigurationCompany']
class Configuration(ModelSingleton, ModelSQL, ModelView):
'Truck Configuration'
__name__ = 'truck.configuration'
order_sequence = fields.Function(fields.Many2One('ir.sequence',
'Order Sequence', domain=[
('code', '=', 'truck.order'),
], required=True),
'get_company_config', setter='set_company_config')
@classmethod
def get_company_config(self, configs, names):
pool = Pool()
CompanyConfig = pool.get('truck.configuration.company')
company_id = Transaction().context.get('company')
company_configs = CompanyConfig.search([
('company', '=', company_id),
])
res = {}
for fname in names:
res[fname] = {
configs[0].id: None,
}
if company_configs:
val = getattr(company_configs[0], fname)
if isinstance(val, Model):
val = val.id
res[fname][configs[0].id] = val
return res
@classmethod
def set_company_config(self, configs, name, value):
pool = Pool()
CompanyConfig = pool.get('truck.configuration.company')
company_id = Transaction().context.get('company')
company_configs = CompanyConfig.search([
('company', '=', company_id),
])
if company_configs:
company_config = company_configs[0]
else:
company_config = CompanyConfig(company=company_id)
setattr(company_config, name, value)
company_config.save()
class ConfigurationCompany(ModelSQL):
'Truck Configuration per Company'
__name__ = 'truck.configuration.company'
company = fields.Many2One('company.company', 'Company', required=True,
ondelete='CASCADE', select=True)
order_sequence = fields.Many2One('ir.sequence',
'Order Sequence', domain=[
('code', '=', 'truck.order'),
])