Fixes on billing
This commit is contained in:
parent
d00befb601
commit
24d0c103a5
2
TODO.md
2
TODO.md
|
@ -412,4 +412,4 @@ touch /tmp/somefile
|
||||||
# batch zone edditing
|
# batch zone edditing
|
||||||
# inherit registers from parent?
|
# inherit registers from parent?
|
||||||
|
|
||||||
# Bill metric disk 5 GB: unialber
|
# Bill metric disk 5 GB: unialber: include not include 5, unialbert recheck period
|
||||||
|
|
|
@ -80,7 +80,10 @@ class OperationsMiddleware(object):
|
||||||
type(self).thread_locals.transaction.__enter__()
|
type(self).thread_locals.transaction.__enter__()
|
||||||
|
|
||||||
def leave_transaction_management(self, exception=None):
|
def leave_transaction_management(self, exception=None):
|
||||||
type(self).thread_locals.transaction.__exit__(exception, None, None)
|
locals = type(self).thread_locals
|
||||||
|
if hasattr(locals, 'transaction'):
|
||||||
|
# Don't fucking know why sometimes thread_locals does not contain a transaction
|
||||||
|
locals.transaction.__exit__(exception, None, None)
|
||||||
|
|
||||||
def process_request(self, request):
|
def process_request(self, request):
|
||||||
""" Store request on a thread local variable """
|
""" Store request on a thread local variable """
|
||||||
|
|
|
@ -51,7 +51,7 @@ class OrderAdmin(AccountAdminMixin, ExtendedModelAdmin):
|
||||||
'id', 'service_link', 'account_link', 'content_object_link',
|
'id', 'service_link', 'account_link', 'content_object_link',
|
||||||
'display_registered_on', 'display_billed_until', 'display_cancelled_on', 'display_metric'
|
'display_registered_on', 'display_billed_until', 'display_cancelled_on', 'display_metric'
|
||||||
)
|
)
|
||||||
list_filter = (ActiveOrderListFilter, IgnoreOrderListFilter, 'service', BilledOrderListFilter)
|
list_filter = (ActiveOrderListFilter, IgnoreOrderListFilter, BilledOrderListFilter, 'service')
|
||||||
default_changelist_filters = (
|
default_changelist_filters = (
|
||||||
('ignore', '0'),
|
('ignore', '0'),
|
||||||
)
|
)
|
||||||
|
|
|
@ -497,20 +497,25 @@ class ServiceHandler(plugins.Plugin, metaclass=plugins.PluginMount):
|
||||||
# Recharge
|
# Recharge
|
||||||
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
|
||||||
charged = None
|
cmetric = None
|
||||||
new_metric, new_price = 0, 0
|
new_metric, new_price = 0, 0
|
||||||
for cini, cend, metric in order.get_metric(rini, bp, changes=True):
|
for cini, cend, metric in order.get_metric(rini, min(bp, order.billed_until), changes=True):
|
||||||
if charged is None:
|
if cmetric is None:
|
||||||
charged = metric
|
cmetric = metric
|
||||||
size = self.get_price_size(cini, cend)
|
cprice = self.get_price(account, cmetric)
|
||||||
new_price += self.get_price(account, metric) * size
|
if metric > cmetric:
|
||||||
new_metric += metric
|
size = self.get_price_size(cini, cend)
|
||||||
size = self.get_price_size(rini, bp)
|
rprice = self.get_price(account, metric)
|
||||||
old_price = self.get_price(account, charged) * size
|
if rprice > cprice:
|
||||||
if new_price > old_price:
|
price = (rprice-cprice) * size
|
||||||
metric = new_metric - charged
|
prepay_discount = cprice*size
|
||||||
price = new_price - old_price
|
discounts = ()
|
||||||
lines.append(self.generate_line(order, price, rini, bp, metric=metric, computed=True))
|
if prepay_discount:
|
||||||
|
discounts = (
|
||||||
|
('prepay', -prepay_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 a new issue