This repository has been archived by the owner on Jan 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
configuration.py
131 lines (107 loc) · 4.47 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
# 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 import backend
from trytond.i18n import gettext
from trytond.model import (
ModelSingleton, ModelSQL, ModelView, MultiValueMixin, ValueMixin, fields)
from trytond.model.exceptions import AccessError
from trytond.pool import Pool
from trytond.pyson import Id
from trytond.tools.multivalue import migrate_property
from .party import IDENTIFIER_TYPES
party_sequence = fields.Many2One('ir.sequence', 'Party Sequence',
domain=[
('sequence_type', '=', Id('party', 'sequence_type_party')),
],
help="Used to generate the party code.")
party_lang = fields.Many2One("ir.lang", 'Party Language',
help="The default language for new parties.")
class Configuration(ModelSingleton, ModelSQL, ModelView, MultiValueMixin):
'Party Configuration'
__name__ = 'party.configuration'
party_sequence = fields.MultiValue(party_sequence)
party_lang = fields.MultiValue(party_lang)
identifier_types = fields.MultiSelection(
IDENTIFIER_TYPES, "Identifier Types",
help="Defines which identifier types are available.\n"
"Leave empty for all of them.")
@classmethod
def default_party_sequence(cls, **pattern):
pool = Pool()
ModelData = pool.get('ir.model.data')
try:
return ModelData.get_id('party', 'sequence_party')
except KeyError:
return None
def get_identifier_types(self):
selection = self.fields_get(
['identifier_types'])['identifier_types']['selection']
if self.identifier_types:
selection = [
(k, v) for k, v in selection if k in self.identifier_types]
return selection
@classmethod
def create(cls, vlist):
records = super().create(vlist)
ModelView._fields_view_get_cache.clear()
return records
@classmethod
def write(cls, *args):
super().write(*args)
ModelView._fields_view_get_cache.clear()
@classmethod
def delete(cls, records):
super().delete(records)
ModelView._fields_view_get_cache.clear()
@classmethod
def validate_fields(cls, records, field_names):
super().validate_fields(records, field_names)
cls(1).check_identifier_types(field_names)
def check_identifier_types(self, field_names=None):
pool = Pool()
Identifier = pool.get('party.identifier')
if field_names and 'identifier_types' not in field_names:
return
if self.identifier_types:
identifier_types = [None, ''] + list(self.identifier_types)
identifiers = Identifier.search([
('type', 'not in', identifier_types),
], limit=1, order=[])
if identifiers:
identifier, = identifiers
selection = self.fields_get(
['identifier_types'])['identifier_types']['selection']
selection = dict(selection)
raise AccessError(gettext(
'party.msg_identifier_type_remove',
type=selection.get(identifier.type, identifier.type),
identifier=identifier.rec_name,
))
class _ConfigurationValue(ModelSQL):
_configuration_value_field = None
@classmethod
def __register__(cls, module_name):
exist = backend.TableHandler.table_exist(cls._table)
super(_ConfigurationValue, cls).__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(
'party.configuration', field_names, cls, value_names,
fields=fields)
class ConfigurationSequence(_ConfigurationValue, ModelSQL, ValueMixin):
'Party Configuration Sequence'
__name__ = 'party.configuration.party_sequence'
party_sequence = party_sequence
_configuration_value_field = 'party_sequence'
@classmethod
def check_xml_record(cls, records, values):
return True
class ConfigurationLang(_ConfigurationValue, ModelSQL, ValueMixin):
'Party Configuration Lang'
__name__ = 'party.configuration.party_lang'
party_lang = party_lang
_configuration_value_field = 'party_lang'