-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.py
60 lines (50 loc) · 2.01 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
#The COPYRIGHT file at the top level of this repository contains the full
#copyright notices and license terms.
from trytond.model import fields
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval, Id
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(metaclass=PoolMeta):
__name__ = 'sale.configuration'
pos_sequence = fields.MultiValue(fields.Many2One(
'ir.sequence.strict', "Sale POS Sequence", required=True,
domain=[
('company', 'in',
[Eval('context', {}).get('company', -1), None]),
('sequence_type', '=', Id('sale_pos', 'sequence_type_sale_pos')),
]))
ticket_report = fields.Many2One('ir.action.report', "Ticket Report")
@classmethod
def __register__(cls, module_name):
super().__register__(module_name)
table = cls.__table_handler__(module_name)
table.not_null_action('ticket_report', action='remove')
@classmethod
def multivalue_model(cls, field):
pool = Pool()
if field == 'pos_sequence':
return pool.get('sale.configuration.sequence')
return super(Configuration, cls).multivalue_model(field)
default_pos_sequence = default_func('pos_sequence')
class ConfigurationSequence(metaclass=PoolMeta):
__name__ = 'sale.configuration.sequence'
pos_sequence = fields.Many2One(
'ir.sequence.strict', "Sale POS Sequence", required=True,
domain=[
('company', 'in', [Eval('company', -1), None]),
('sequence_type', '=', Id('sale_pos', 'sequence_type_sale_pos')),
])
@classmethod
def default_pos_sequence(cls):
pool = Pool()
ModelData = pool.get('ir.model.data')
try:
return ModelData.get_id('sale_pos', 'sequence_sale_pos')
except KeyError:
return None