This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfiguration.py
74 lines (61 loc) · 2.52 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
# 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.model import ModelSQL, ValueMixin, fields
from trytond.pool import Pool, PoolMeta
sale_under_shipment_tolerance = fields.Float(
"Sale Under Shipment Tolerance",
help="The lower quantity accepted in percentage.")
sale_over_shipment_tolerance = fields.Float(
"Sale Over Shipment Tolerance",
help="The upper quantity accepted in percentage.")
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'
sale_under_shipment_tolerance = fields.MultiValue(
sale_under_shipment_tolerance)
sale_over_shipment_tolerance = fields.MultiValue(
sale_over_shipment_tolerance)
@classmethod
def multivalue_model(cls, field):
pool = Pool()
if field in {
'sale_under_shipment_tolerance',
'sale_over_shipment_tolerance'}:
return pool.get('sale.configuration.shipment_tolerance')
return super(Configuration, cls).multivalue_model(field)
default_sale_under_shipment_tolerance = default_func(
'sale_under_shipment_tolerance')
default_sale_over_shipment_tolerance = default_func(
'sale_over_shipment_tolerance')
class ConfigurationShipmentTolerance(ModelSQL, ValueMixin):
"Sale Configuration Shipment Tolerance"
__name__ = 'sale.configuration.shipment_tolerance'
sale_under_shipment_tolerance = sale_under_shipment_tolerance
sale_over_shipment_tolerance = sale_over_shipment_tolerance
@classmethod
def __setup__(cls):
super(ConfigurationShipmentTolerance, cls).__setup__()
cls.sale_under_shipment_tolerance.domain = [
'OR',
('sale_under_shipment_tolerance', '=', None),
[
('sale_under_shipment_tolerance', '>=', 0),
('sale_under_shipment_tolerance', '<=', 1),
]]
cls.sale_over_shipment_tolerance.domain = [
'OR',
('sale_over_shipment_tolerance', '=', None),
('sale_over_shipment_tolerance', '>=', 1),
]
@classmethod
def default_sale_under_shipment_tolerance(cls):
return 1
@classmethod
def default_sale_over_shipment_tolerance(cls):
return None