This repository was archived by the owner on Dec 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconfiguration.py
More file actions
133 lines (111 loc) · 4.72 KB
/
Copy pathconfiguration.py
File metadata and controls
133 lines (111 loc) · 4.72 KB
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
# 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.model import (
ModelSingleton, ModelSQL, ModelView, ValueMixin, fields)
from trytond.modules.company.model import (
CompanyMultiValueMixin, CompanyValueMixin)
from trytond.pool import Pool
from trytond.pyson import Eval, Id, TimeDelta
from trytond.tools.multivalue import migrate_property
purchase_invoice_method = fields.Selection(
'get_purchase_invoice_method', "Invoice Method")
def get_purchase_methods(field_name):
@classmethod
def func(cls):
pool = Pool()
Purchase = pool.get('purchase.purchase')
return Purchase.fields_get([field_name])[field_name]['selection']
return func
class Configuration(
ModelSingleton, ModelSQL, ModelView, CompanyMultiValueMixin):
'Purchase Configuration'
__name__ = 'purchase.configuration'
purchase_sequence = fields.MultiValue(fields.Many2One(
'ir.sequence', "Purchase Sequence", required=True,
domain=[
('company', 'in',
[Eval('context', {}).get('company', -1), None]),
('sequence_type', '=',
Id('purchase', 'sequence_type_purchase')),
]))
purchase_invoice_method = fields.MultiValue(purchase_invoice_method)
get_purchase_invoice_method = get_purchase_methods('invoice_method')
purchase_process_after = fields.TimeDelta(
"Process Purchase after",
domain=['OR',
('purchase_process_after', '=', None),
('purchase_process_after', '>=', TimeDelta()),
],
help="The grace period during which confirmed purchase "
"can still be reset to draft.\n"
"Applied only if a worker queue is activated.")
@classmethod
def multivalue_model(cls, field):
pool = Pool()
if field == 'purchase_invoice_method':
return pool.get('purchase.configuration.purchase_method')
if field == 'purchase_sequence':
return pool.get('purchase.configuration.sequence')
return super(Configuration, cls).multivalue_model(field)
@classmethod
def default_purchase_sequence(cls, **pattern):
return cls.multivalue_model(
'purchase_sequence').default_purchase_sequence()
@classmethod
def default_purchase_invoice_method(cls, **pattern):
return cls.multivalue_model(
'purchase_invoice_method').default_purchase_invoice_method()
class ConfigurationSequence(ModelSQL, CompanyValueMixin):
"Purchase Configuration Sequence"
__name__ = 'purchase.configuration.sequence'
purchase_sequence = fields.Many2One(
'ir.sequence', "Purchase Sequence", required=True,
domain=[
('company', 'in', [Eval('company', -1), None]),
('sequence_type', '=',
Id('purchase', 'sequence_type_purchase')),
])
@classmethod
def __register__(cls, module_name):
exist = backend.TableHandler.table_exist(cls._table)
super(ConfigurationSequence, cls).__register__(module_name)
if not exist:
cls._migrate_property([], [], [])
@classmethod
def _migrate_property(cls, field_names, value_names, fields):
field_names.append('purchase_sequence')
value_names.append('purchase_sequence')
fields.append('company')
migrate_property(
'purchase.configuration', field_names, cls, value_names,
fields=fields)
@classmethod
def default_purchase_sequence(cls):
pool = Pool()
ModelData = pool.get('ir.model.data')
try:
return ModelData.get_id('purchase', 'sequence_purchase')
except KeyError:
return None
class ConfigurationPurchaseMethod(ModelSQL, ValueMixin):
"Purchase Configuration Purchase Method"
__name__ = 'purchase.configuration.purchase_method'
purchase_invoice_method = purchase_invoice_method
get_purchase_invoice_method = get_purchase_methods('invoice_method')
@classmethod
def __register__(cls, module_name):
exist = backend.TableHandler.table_exist(cls._table)
super(ConfigurationPurchaseMethod, cls).__register__(module_name)
if not exist:
cls._migrate_property([], [], [])
@classmethod
def _migrate_property(cls, field_names, value_names, fields):
field_names.append('purchase_invoice_method')
value_names.append('purchase_invoice_method')
migrate_property(
'purchase.configuration', field_names, cls, value_names,
fields=fields)
@classmethod
def default_purchase_invoice_method(cls):
return 'order'