Fixes on billing
This commit is contained in:
parent
24d0c103a5
commit
524ca5faae
|
@ -498,24 +498,26 @@ class ServiceHandler(plugins.Plugin, metaclass=plugins.PluginMount):
|
||||||
if self.payment_style == self.PREPAY and order.billed_on:
|
if self.payment_style == self.PREPAY and order.billed_on:
|
||||||
rini = order.billed_on
|
rini = order.billed_on
|
||||||
cmetric = None
|
cmetric = None
|
||||||
new_metric, new_price = 0, 0
|
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, min(bp, order.billed_until), changes=True):
|
||||||
if cmetric is None:
|
if cmetric is None:
|
||||||
cmetric = metric
|
cmetric = metric
|
||||||
cprice = self.get_price(account, cmetric)
|
cprice = self.get_price(account, cmetric)
|
||||||
if metric > cmetric:
|
csize = self.get_price_size(rini, order.billed_until)
|
||||||
|
acc_discount += cprice*csize
|
||||||
size = self.get_price_size(cini, cend)
|
size = self.get_price_size(cini, cend)
|
||||||
rprice = self.get_price(account, metric)
|
rprice = self.get_price(account, metric)
|
||||||
if rprice > cprice:
|
|
||||||
price = (rprice-cprice) * size
|
price = (rprice-cprice) * size
|
||||||
prepay_discount = cprice*size
|
|
||||||
discounts = ()
|
discounts = ()
|
||||||
if prepay_discount:
|
pre_discount = min(price, max(acc_discount, 0))
|
||||||
|
if pre_discount:
|
||||||
|
acc_discount -= price
|
||||||
discounts = (
|
discounts = (
|
||||||
('prepay', -prepay_discount),
|
('prepay', -pre_discount),
|
||||||
)
|
)
|
||||||
lines.append(self.generate_line(order, price, cini, cend,
|
# if price-pre_discount:
|
||||||
metric=metric, computed=True, discounts=discounts))
|
lines.append(self.generate_line(order, price, cini, cend, metric=metric,
|
||||||
|
computed=True, discounts=discounts))
|
||||||
if order.billed_until and order.cancelled_on and order.cancelled_on >= order.billed_until:
|
if order.billed_until and order.cancelled_on and order.cancelled_on >= order.billed_until:
|
||||||
continue
|
continue
|
||||||
if self.billing_period != self.NEVER:
|
if self.billing_period != self.NEVER:
|
||||||
|
|
Loading…
Reference in New Issue