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
|
||||||
|
cprice = self.get_price(account, cmetric)
|
||||||
|
if metric > cmetric:
|
||||||
size = self.get_price_size(cini, cend)
|
size = self.get_price_size(cini, cend)
|
||||||
new_price += self.get_price(account, metric) * size
|
rprice = self.get_price(account, metric)
|
||||||
new_metric += metric
|
if rprice > cprice:
|
||||||
size = self.get_price_size(rini, bp)
|
price = (rprice-cprice) * size
|
||||||
old_price = self.get_price(account, charged) * size
|
prepay_discount = cprice*size
|
||||||
if new_price > old_price:
|
discounts = ()
|
||||||
metric = new_metric - charged
|
if prepay_discount:
|
||||||
price = new_price - old_price
|
discounts = (
|
||||||
lines.append(self.generate_line(order, price, rini, bp, metric=metric, computed=True))
|
('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 New Issue