-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshipper.py
executable file
·100 lines (83 loc) · 2.88 KB
/
shipper.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
"""
Post Danmark shipping module
v 0.1
By Jakob Torp Svendsen - googletorp
- This module is still in development
"""
try:
from decimal import Decimal
except:
from django.utils._decimal import Decimal
from django.utils.translation import ugettext as _
from livesettings import config_get_group
from shipping.modules.base import BaseShipper
from shipping.modules.postdk.helper import pack_parcels
# Fees as per January 1st, 2009.
POSTDK_FEES = {
'max_5': Decimal("75.00"),
'max_10': Decimal("100.00"),
'max_20': Decimal("160.00"),
'volume': Decimal("76.00"),
'fragile': Decimal("76.00"),
}
class Shipper(BaseShipper):
id = "PostDK"
def __str__(self):
"""
This is mainly helpful for debugging purposes.
"""
return "Post Danmark"
def description(self):
"""
A basic description that will be displayed to the user, when
selecting their shipping options.
"""
return _("Post Danmark shipping")
def cost(self):
"""
Complex calculations can be done here, as long as the return value is
a decimal figure.
"""
cartset = self.cart.cartitem_set.all()
settings = config_get_group('shipping.modules.postdk')
parcel_list = pack_parcels(cartset, settings)
result = Decimal("0.00")
for parcel in parcel_list:
if parcel.weight <= 5:
result += POSTDK_FEES['max_5']
elif parcel.weight <= 10:
result += POSTDK_FEES['max_10']
elif parcel.weight <= 20:
result += POSTDK_FEES['max_20']
else:
# TODO, raise error as we currently don't accept parcels over
# 20 kg, or parcel has no weight.
pass
if parcel.volume_fee():
result += POSTDK_FEES['volume']
result += settings['POSTDK_HANDLING'].value
result *= settings['POSTDK_CURRENCY'].value
return result
def method(self):
"""
Describes the actual delivery service (Mail, FedEx, DHL, UPS, etc).
"""
return _("Post Danmark")
def expectedDelivery(self):
"""
Can be a plain string or complex calcuation returning an actual date.
"""
return settings['POSTDK_DAYS'].value
def valid(self, order=None):
"""
Can do complex validation about whether or not this option is valid.
For example, may check to see if the recipient is in an allowed
country or location.
"""
# Only allow sending to Denmark for now. This is not a good way of
# doing this, as it will simply disable the module.
# TODO Need to figure out how to do better error handling with
# satchmo.
if not self.contact.shipping_address.country_id == 59:
return False
return True