-
Notifications
You must be signed in to change notification settings - Fork 5
/
carrier.py
81 lines (63 loc) · 2.21 KB
/
carrier.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
# -*- coding: utf-8 -*-
"""
carrier.py
:copyright: (c) 2014 by Openlabs Technologies & Consulting (P) Limited
:license: BSD, see LICENSE for more details.
"""
from trytond import backend
from trytond.pool import PoolMeta, Pool
from trytond.model import ModelView, ModelSQL, ModelSingleton, fields
from trytond.transaction import Transaction
__all__ = ['Carrier', 'CarrierConfig']
__metaclass__ = PoolMeta
class CarrierConfig(ModelSingleton, ModelSQL, ModelView):
"Carrier Configuration"
__name__ = 'carrier.configuration'
default_validation_carrier = fields.Many2One(
'carrier', 'Default Validation Carrier'
)
@classmethod
def __register__(cls, module_name):
super(CarrierConfig, cls).__register__(module_name)
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
table = TableHandler(cursor, cls, module_name)
if table.column_exist('default_validation_provider'):
table.drop_column('default_validation_provider')
@classmethod
def __setup__(cls):
super(CarrierConfig, cls).__setup__()
carrier_cost_methods = cls.get_carrier_methods_for_domain()
cls.default_validation_carrier.domain = [
('carrier_cost_method', 'in', carrier_cost_methods)
]
@classmethod
def get_carrier_methods_for_domain(cls):
"""
Return the list of carrier methods that can be used for
address validation
"""
return []
class Carrier:
"Carrier"
__name__ = 'carrier'
currency = fields.Many2One('currency.currency', 'Currency', required=True)
@staticmethod
def default_currency():
Company = Pool().get('company.company')
company = Transaction().context.get('company')
if company:
return Company(company).currency.id
def get_rates(self):
"""
Expects a list of tuples as:
[
(
<display method name>, <rate>, <currency>, <metadata>,
<write_vals>
)
...
]
Downstream shipping modules can implement this to get shipping rates.
"""
return [] # pragma: no cover