forked from trytonus/trytond-shipping-dpd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sale.py
120 lines (100 loc) · 3.21 KB
/
sale.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
# -*- coding: utf-8 -*-
"""
sale.py
"""
from trytond.pool import PoolMeta, Pool
from trytond.model import fields
from trytond.pyson import Eval, Bool, And
__all__ = ['Sale', 'SaleConfiguration']
__metaclass__ = PoolMeta
STATES = {
'readonly': Eval('state') == 'done',
'required': Bool(Eval('is_dpd_shipping')),
}
DPD_PRODUCTS = [
(None, ''),
('CL', 'DPD CLASSIC'),
('E830', 'DPD 8:30'),
('E10', 'DPD 10:00'),
('E12', 'DPD 12:00'),
('E18', 'DPD 18:00'),
('IE2', 'DPD EXPRESS'),
('PL', 'DPD PARCELLetter'),
('PL+', 'DPD PARCELLetterPlus'),
('MAIL', 'DPD International Mail'),
]
class SaleConfiguration:
'Sale Configuration'
__name__ = 'sale.configuration'
dpd_product = fields.Selection(
DPD_PRODUCTS, 'DPD Product'
)
@staticmethod
def default_dpd_product():
return 'CL'
class Sale:
"Sale"
__name__ = 'sale.sale'
is_dpd_shipping = fields.Function(
fields.Boolean('Is Shipping', readonly=True),
'get_is_dpd_shipping'
)
dpd_product = fields.Selection(
DPD_PRODUCTS, 'DPD Product', states=STATES, depends=[
'state', 'is_dpd_shipping'
]
)
dpd_customs_terms = fields.Selection(
[
(None, ''),
('01', 'DAP, cleared'),
('02', 'DDP, delivered duty paid (incl. duties and excl. Taxes'),
(
'03',
'DDP, delivered duty paid (incl duties and taxes) 05 = ex '
'works (EXW)'
),
('06', 'DAP'),
], 'DPD customs terms', states={
'readonly': Eval('state') == 'done',
'invisible': ~Eval('is_international_shipping'),
'required': And(
Bool(Eval('is_dpd_shipping')),
Bool(Eval('is_international_shipping'))
),
}, depends=['state', 'dpd_product']
)
@classmethod
def view_attributes(cls):
return super(Sale, cls).view_attributes() + [
('//page[@id="dpd"]', 'states', {
'invisible': ~Bool(Eval('is_dpd_shipping'))
})]
@staticmethod
def default_dpd_product():
Config = Pool().get('sale.configuration')
config = Config(1)
return config.dpd_product
@fields.depends('is_dpd_shipping', 'carrier')
def on_change_carrier(self):
"""
Show/Hide DPD Tab in view on change of carrier
"""
super(Sale, self).on_change_carrier()
self.is_dpd_shipping = self.carrier and \
self.carrier.carrier_cost_method == 'dpd' or None
def get_is_dpd_shipping(self, name):
"""
Check if shipping is from DPD
"""
return self.carrier and self.carrier.carrier_cost_method == 'dpd'
def _get_shipment_sale(self, Shipment, key):
"""
Downstream implementation which adds dpd-specific fields to the unsaved
Shipment record.
"""
shipment = super(Sale, self)._get_shipment_sale(Shipment, key)
if Shipment.__name__ == 'stock.shipment.out' and self.is_dpd_shipping:
shipment.dpd_customs_terms = self.dpd_customs_terms
shipment.dpd_product = self.dpd_product
return shipment