-
Notifications
You must be signed in to change notification settings - Fork 6
/
configuration.py
163 lines (137 loc) · 6 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# This file is part of the cooperative_ar module for Tryton.
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
from trytond.model import ModelView, ModelSQL, ModelSingleton, fields
from trytond.pool import Pool
from trytond.pyson import Eval, Id
from trytond.tools.multivalue import migrate_property
from trytond.modules.company.model import (
CompanyMultiValueMixin, CompanyValueMixin)
def default_func(field_name):
@classmethod
def default(cls, **pattern):
return getattr(
cls.multivalue_model(field_name),
'default_%s' % field_name, lambda: None)()
return default
class Configuration(
ModelSingleton, ModelSQL, ModelView, CompanyMultiValueMixin):
'Cooperative Configuration'
__name__ = 'cooperative_ar.configuration'
receipt_account_receivable = fields.MultiValue(fields.Many2One(
'account.account', "Default Account Receivable",
domain=[
('company', '=', Eval('context', {}).get('company', -1)),
]))
receipt_account_payable = fields.MultiValue(fields.Many2One(
'account.account', "Default Account Payable",
domain=[
('company', '=', Eval('context', {}).get('company', -1)),
]))
recibo_sequence = fields.MultiValue(fields.Many2One(
'ir.sequence', "Recibo Sequence", required=True,
domain=[
('sequence_type', '=',
Id('cooperative_ar', 'sequence_type_recibo')),
('company', 'in',
[Eval('context', {}).get('company', -1), None]),
]))
recibo_lote_sequence = fields.MultiValue(fields.Many2One(
'ir.sequence', "Recibo Lote Sequence", required=True,
domain=[
('sequence_type', '=',
Id('cooperative_ar', 'sequence_type_recibo')),
('company', 'in',
[Eval('context', {}).get('company', -1), None]),
]))
@classmethod
def multivalue_model(cls, field):
pool = Pool()
if field in {'receipt_account_receivable', 'receipt_account_payable'}:
return pool.get('cooperative_ar.configuration.receipt_account')
if field in {'recibo_sequence', 'recibo_lote_sequence'}:
return pool.get('cooperative_ar.configuration.sequence')
return super().multivalue_model(field)
default_recibo_sequence = default_func('recibo_sequence')
default_recibo_lote_sequence = default_func('recibo_lote_sequence')
class _ConfigurationValue(ModelSQL):
_configuration_value_field = None
@classmethod
def __register__(cls, module_name):
table_h = cls.__table_handler__(module_name)
exist = table_h.table_exist(cls._table)
super().__register__(module_name)
if not exist:
cls._migrate_property([], [], [])
@classmethod
def _migrate_property(cls, field_names, value_names, fields):
field_names.append(cls._configuration_value_field)
value_names.append(cls._configuration_value_field)
migrate_property(
'cooperative_ar.configuration', field_names, cls, value_names,
fields=fields)
class ConfigurationSequence(_ConfigurationValue, ModelSQL, CompanyValueMixin):
'Receipt Configuration Sequence'
__name__ = 'cooperative_ar.configuration.sequence'
recibo_sequence = fields.Many2One(
'ir.sequence', "Recibo Sequence", required=True,
domain=[
('sequence_type', '=',
Id('cooperative_ar', 'sequence_type_recibo')),
('company', 'in', [Eval('company', -1), None]),
],
depends=['company'])
recibo_lote_sequence = fields.Many2One(
'ir.sequence', "Recibo Lote Sequence", required=True,
domain=[
('sequence_type', '=',
Id('cooperative_ar', 'sequence_type_recibo')),
('company', 'in', [Eval('company', -1), None]),
],
depends=['company'])
_configuration_value_field = 'recibo_sequence'
_configuration_value_field = 'recibo_lote_sequence'
@classmethod
def default_recibo_sequence(cls):
pool = Pool()
ModelData = pool.get('ir.model.data')
try:
return ModelData.get_id('cooperative_ar', 'sequence_recibo')
except KeyError:
return None
@classmethod
def default_recibo_lote_sequence(cls):
pool = Pool()
ModelData = pool.get('ir.model.data')
try:
return ModelData.get_id('cooperative_ar', 'sequence_recibo_lote')
except KeyError:
return None
class ConfigurationReceiptAccount(ModelSQL, CompanyValueMixin):
"Account Configuration Receipt Account"
__name__ = 'cooperative_ar.configuration.receipt_account'
receipt_account_receivable = fields.Many2One(
'account.account', "Receipt Account Receivable",
domain=[
('company', '=', Eval('context', {}).get('company', -1)),
],
depends=['company'])
receipt_account_payable = fields.Many2One(
'account.account', "Receipt Account Payable",
domain=[
('company', '=', Eval('context', {}).get('company', -1)),
],
depends=['company'])
class ConfigurationSkill(ModelSingleton, ModelSQL, ModelView):
'Cooperative Skill Configuration'
__name__ = 'cooperative_ar.configuration.skill'
skill_01 = fields.Numeric('Skill 1 %', digits=(16, 2))
skill_02 = fields.Numeric('Skill 2 %', digits=(16, 2))
skill_03 = fields.Numeric('Skill 3 %', digits=(16, 2))
skill_04 = fields.Numeric('Skill 4 %', digits=(16, 2))
skill_05 = fields.Numeric('Skill 5 %', digits=(16, 2))
skill_06 = fields.Numeric('Skill 6 %', digits=(16, 2))
skill_07 = fields.Numeric('Skill 7 %', digits=(16, 2))
skill_08 = fields.Numeric('Skill 8 %', digits=(16, 2))
skill_09 = fields.Numeric('Skill 9 %', digits=(16, 2))
skill_10 = fields.Numeric('Skill 10 %', digits=(16, 2))