From ca6b479e174d3eba2c62710ed2d6370adae80fb3 Mon Sep 17 00:00:00 2001 From: Marc Aymerich Date: Tue, 26 May 2015 19:49:09 +0000 Subject: [PATCH] Fixes on billing --- orchestra/contrib/services/handlers.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/orchestra/contrib/services/handlers.py b/orchestra/contrib/services/handlers.py index 85005fdc..8fb6d26f 100644 --- a/orchestra/contrib/services/handlers.py +++ b/orchestra/contrib/services/handlers.py @@ -497,23 +497,21 @@ class ServiceHandler(plugins.Plugin, metaclass=plugins.PluginMount): # Recharge if self.payment_style == self.PREPAY and order.billed_on: rini = order.billed_on + rend = min(bp, order.billed_until) cmetric = None - acc_discount = 0 - for cini, cend, metric in order.get_metric(rini, min(bp, order.billed_until), changes=True): + for cini, cend, metric in order.get_metric(rini, rend, changes=True): if cmetric is None: cmetric = metric - cprice = self.get_price(account, cmetric) csize = self.get_price_size(rini, order.billed_until) - acc_discount += cprice*csize + cprice = self.get_price(account, cmetric) * csize size = self.get_price_size(cini, cend) - rprice = self.get_price(account, metric) - price = (rprice-cprice) * size + price = self.get_price(account, metric) * size discounts = () - pre_discount = min(price, max(acc_discount, 0)) + discount = min(price, max(cprice, 0)) if pre_discount: - acc_discount -= price + cprice -= price discounts = ( - ('prepay', -pre_discount), + ('prepay', -discount), ) # if price-pre_discount: lines.append(self.generate_line(order, price, cini, cend, metric=metric,