|
|
@@ -2,9 +2,10 @@ from django.contrib.sites.models import Site
|
|
2
|
2
|
|
|
3
|
3
|
from oscar.core.loading import import_module
|
|
4
|
4
|
import_module('order.models', ['ShippingAddress', 'Order', 'Line',
|
|
5
|
|
- 'LinePrice', 'LineAttribute', 'OrderDiscount'], locals())
|
|
|
5
|
+ 'LinePrice', 'LineAttribute', 'OrderDiscount'], locals())
|
|
6
|
6
|
import_module('order.signals', ['order_placed'], locals())
|
|
7
|
7
|
|
|
|
8
|
+
|
|
8
|
9
|
class OrderNumberGenerator(object):
|
|
9
|
10
|
u"""
|
|
10
|
11
|
Simple object for generating order numbers.
|
|
|
@@ -47,7 +48,7 @@ class OrderCreator(object):
|
|
47
|
48
|
basket.set_as_submitted()
|
|
48
|
49
|
|
|
49
|
50
|
# Send signal for analytics to pick up
|
|
50
|
|
- order_signals.order_placed.send(sender=self, order=order, user=user)
|
|
|
51
|
+ order_placed.send(sender=self, order=order, user=user)
|
|
51
|
52
|
|
|
52
|
53
|
return order
|
|
53
|
54
|
|
|
|
@@ -77,18 +78,29 @@ class OrderCreator(object):
|
|
77
|
78
|
|
|
78
|
79
|
def _create_line_models(self, order, basket_line):
|
|
79
|
80
|
u"""Creates the batch line model."""
|
|
80
|
|
- order_line = order_models.Line(order=order,
|
|
81
|
|
- partner=self._get_partner_for_product(basket_line.product),
|
|
82
|
|
- product=basket_line.product,
|
|
83
|
|
- title=basket_line.product.get_title(),
|
|
84
|
|
- quantity=basket_line.quantity,
|
|
85
|
|
- line_price_excl_tax=basket_line.line_price_excl_tax_and_discounts,
|
|
86
|
|
- line_price_incl_tax=basket_line.line_price_incl_tax_and_discounts,
|
|
87
|
|
- line_price_before_discounts_excl_tax=basket_line.line_price_excl_tax,
|
|
88
|
|
- line_price_before_discounts_incl_tax=basket_line.line_price_incl_tax,)
|
|
89
|
|
- if basket_line.product.has_stockrecord:
|
|
90
|
|
- order_line.partner_sku = basket_line.product.stockrecord.partner_sku
|
|
91
|
|
- order_line.est_dispatch_date = basket_line.product.stockrecord.dispatch_date
|
|
|
81
|
+ partner = self._get_partner_for_product(basket_line.product)
|
|
|
82
|
+ stockrecord = basket_line.product.stockrecord
|
|
|
83
|
+ order_line = Line(order=order,
|
|
|
84
|
+ # Partner details
|
|
|
85
|
+ partner=partner,
|
|
|
86
|
+ partner_name=partner.name,
|
|
|
87
|
+ partner_sku=stockrecord.partner_sku,
|
|
|
88
|
+ # Product details
|
|
|
89
|
+ product=basket_line.product,
|
|
|
90
|
+ title=basket_line.product.get_title(),
|
|
|
91
|
+ quantity=basket_line.quantity,
|
|
|
92
|
+ # Price details
|
|
|
93
|
+ line_price_excl_tax=basket_line.line_price_excl_tax_and_discounts,
|
|
|
94
|
+ line_price_incl_tax=basket_line.line_price_incl_tax_and_discounts,
|
|
|
95
|
+ line_price_before_discounts_excl_tax=basket_line.line_price_excl_tax,
|
|
|
96
|
+ line_price_before_discounts_incl_tax=basket_line.line_price_incl_tax,
|
|
|
97
|
+ # Reporting details
|
|
|
98
|
+ unit_cost_price = stockrecord.cost_price,
|
|
|
99
|
+ unit_site_price = stockrecord.price_incl_tax,
|
|
|
100
|
+ unit_retail_price = stockrecord.price_retail,
|
|
|
101
|
+ # Shipping details
|
|
|
102
|
+ est_dispatch_date = basket_line.product.stockrecord.dispatch_date
|
|
|
103
|
+ )
|
|
92
|
104
|
order_line.save()
|
|
93
|
105
|
self._create_line_price_models(order, order_line, basket_line)
|
|
94
|
106
|
self._create_line_attributes(order, order_line, basket_line)
|
|
|
@@ -98,18 +110,18 @@ class OrderCreator(object):
|
|
98
|
110
|
breakdown = basket_line.get_price_breakdown()
|
|
99
|
111
|
for price_incl_tax, price_excl_tax, quantity in breakdown:
|
|
100
|
112
|
LinePrice._default_manager.create(order=order,
|
|
101
|
|
- line=order_line,
|
|
102
|
|
- quantity=quantity,
|
|
103
|
|
- price_incl_tax=price_incl_tax,
|
|
104
|
|
- price_excl_tax=price_excl_tax)
|
|
|
113
|
+ line=order_line,
|
|
|
114
|
+ quantity=quantity,
|
|
|
115
|
+ price_incl_tax=price_incl_tax,
|
|
|
116
|
+ price_excl_tax=price_excl_tax)
|
|
105
|
117
|
|
|
106
|
118
|
def _create_line_attributes(self, order, order_line, basket_line):
|
|
107
|
119
|
u"""Creates the batch line attributes."""
|
|
108
|
120
|
for attr in basket_line.attributes.all():
|
|
109
|
121
|
LineAttribute._default_manager.create(line=order_line,
|
|
110
|
|
- option=attr.option,
|
|
111
|
|
- type=attr.option.code,
|
|
112
|
|
- value=attr.value)
|
|
|
122
|
+ option=attr.option,
|
|
|
123
|
+ type=attr.option.code,
|
|
|
124
|
+ value=attr.value)
|
|
113
|
125
|
|
|
114
|
126
|
def _create_discount_model(self, order, discount):
|
|
115
|
127
|
u"""
|