Преглед изворни кода

Use database aggregation to calculate basket totals before discount. (#3576)

master
jolob5l пре 5 година
родитељ
комит
310f82ea51
No account linked to committer's email address
1 измењених фајлова са 4 додато и 8 уклоњено
  1. 4
    8
      src/oscar/apps/order/abstract_models.py

+ 4
- 8
src/oscar/apps/order/abstract_models.py Прегледај датотеку

@@ -166,20 +166,16 @@ class AbstractOrder(models.Model):
166 166
         """
167 167
         Return basket total including tax but before discounts are applied
168 168
         """
169
-        total = D('0.00')
170
-        for line in self.lines.all():
171
-            total += line.line_price_before_discounts_incl_tax
172
-        return total
169
+        result = self.lines.aggregate(total=Sum('line_price_before_discounts_incl_tax'))
170
+        return result['total']
173 171
 
174 172
     @property
175 173
     def basket_total_before_discounts_excl_tax(self):
176 174
         """
177 175
         Return basket total excluding tax but before discounts are applied
178 176
         """
179
-        total = D('0.00')
180
-        for line in self.lines.all():
181
-            total += line.line_price_before_discounts_excl_tax
182
-        return total
177
+        result = self.lines.aggregate(total=Sum('line_price_before_discounts_excl_tax'))
178
+        return result['total']
183 179
 
184 180
     @property
185 181
     def basket_total_incl_tax(self):

Loading…
Откажи
Сачувај