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)
|
||||||
size = self.get_price_size(cini, cend)
|
acc_discount += cprice*csize
|
||||||
rprice = self.get_price(account, metric)
|
size = self.get_price_size(cini, cend)
|
||||||
if rprice > cprice:
|
rprice = self.get_price(account, metric)
|
||||||
price = (rprice-cprice) * size
|
price = (rprice-cprice) * size
|
||||||
prepay_discount = cprice*size
|
discounts = ()
|
||||||
discounts = ()
|
pre_discount = min(price, max(acc_discount, 0))
|
||||||
if prepay_discount:
|
if pre_discount:
|
||||||
discounts = (
|
acc_discount -= price
|
||||||
('prepay', -prepay_discount),
|
discounts = (
|
||||||
)
|
('prepay', -pre_discount),
|
||||||
lines.append(self.generate_line(order, price, cini, cend,
|
)
|
||||||
metric=metric, computed=True, discounts=discounts))
|
# if price-pre_discount:
|
||||||
|
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