Improvements on order billing

This commit is contained in:
Marc 2014-09-14 22:00:00 +00:00
parent 6533331461
commit 53b1391b1d
3 changed files with 56 additions and 56 deletions

View File

@ -47,8 +47,8 @@ class ServiceAdmin(admin.ModelAdmin):
(_("Pricing options"), {
'classes': ('wide',),
'fields': ('metric', 'pricing_period', 'rate_algorithm',
'orders_effect', 'on_cancel', 'payment_style',
'trial_period', 'refound_period', 'tax', 'nominal_price')
'on_cancel', 'payment_style',
'tax', 'nominal_price')
}),
)
inlines = [RateInline]

View File

@ -192,28 +192,32 @@ class ServiceHandler(plugins.Plugin):
end = max(end, bp) # TODO if all bp are the same ...
related_orders = Order.objects.filter(service=self.service, account=account)
if self.on_cancel in (self.COMPENSATE, self.REFOUND):
if self.on_cancel == self.COMPENSATE:
# Get orders pending for compensation
givers = related_orders.filter_givers(ini, end)
givers.sort(cmp=helpers.cmp_billed_until_or_registered_on)
orders.sort(cmp=helpers.cmp_billed_until_or_registered_on)
self.compensate(givers, orders)
# Get pricing orders
porders = related_orders.filter_pricing_orders(ini, end)
porders = set(orders).union(set(porders))
for ini, end, orders in self.get_chunks(porders, ini, end):
if self.pricing_period == self.ANUAL:
pass
elif self.pricing_period == self.MONTHLY:
pass
else:
raise NotImplementedError
metric = len(orders)
for position, order in enumerate(orders):
# TODO position +1?
price = self.get_price(order, metric, position=position)
price *= size
rates = 'TODO'
if rates:
# Get pricing orders
porders = related_orders.filter_pricing_orders(ini, end)
porders = set(orders).union(set(porders))
for ini, end, orders in self.get_chunks(porders, ini, end):
if self.pricing_period == self.ANUAL:
pass
elif self.pricing_period == self.MONTHLY:
pass
else:
raise NotImplementedError
metric = len(orders)
for position, order in enumerate(orders):
# TODO position +1?
price = self.get_price(order, metric, position=position)
price *= size
else:
pass
def compensate(self, givers, receivers):
compensations = []

View File

@ -116,14 +116,14 @@ class Service(models.Model):
(FIXED_DATE, _("Fixed billing date")),
),
default=FIXED_DATE)
delayed_billing = models.CharField(_("delayed billing"), max_length=16,
help_text=_("Period in which this service will be ignored for billing"),
choices=(
(NEVER, _("No delay (inmediate billing)")),
(TEN_DAYS, _("Ten days")),
(ONE_MONTH, _("One month")),
),
default=ONE_MONTH, blank=True)
# delayed_billing = models.CharField(_("delayed billing"), max_length=16,
# help_text=_("Period in which this service will be ignored for billing"),
# choices=(
# (NEVER, _("No delay (inmediate billing)")),
# (TEN_DAYS, _("Ten days")),
# (ONE_MONTH, _("One month")),
# ),
# default=ONE_MONTH, blank=True)
is_fee = models.BooleanField(_("is fee"), default=False,
help_text=_("Designates whether this service should be billed as "
" membership fee or not"))
@ -152,24 +152,20 @@ class Service(models.Model):
(MATCH_PRICE, _("Match price")),
),
default=BEST_PRICE)
# TODO remove since it can be infered from pricing period?
# VARIABLE -> REGISTER_OR_RENEW
# FIXED -> CONCURRENT
orders_effect = models.CharField(_("orders effect"), max_length=16,
help_text=_("Defines the lookup behaviour when using orders for "
"the pricing rate computation of this service."),
choices=(
(REGISTER_OR_RENEW, _("Register or renew events")),
(CONCURRENT, _("Active at every given time")),
),
default=CONCURRENT)
# orders_effect = models.CharField(_("orders effect"), max_length=16,
# help_text=_("Defines the lookup behaviour when using orders for "
# "the pricing rate computation of this service."),
# choices=(
# (REGISTER_OR_RENEW, _("Register or renew events")),
# (CONCURRENT, _("Active at every given time")),
# ),
# default=CONCURRENT)
on_cancel = models.CharField(_("on cancel"), max_length=16,
help_text=_("Defines the cancellation behaviour of this service"),
choices=(
(NOTHING, _("Nothing")),
(DISCOUNT, _("Discount")),
(COMPENSATE, _("Discount and compensate")),
(REFOUND, _("Discount, compensate and refound")),
),
default=DISCOUNT)
payment_style = models.CharField(_("payment style"), max_length=16,
@ -180,24 +176,24 @@ class Service(models.Model):
(POSTPAY, _("Postpay (on demand)")),
),
default=PREPAY)
trial_period = models.CharField(_("trial period"), max_length=16, blank=True,
help_text=_("Period in which no charge will be issued"),
choices=(
(NEVER, _("No trial")),
(TEN_DAYS, _("Ten days")),
(ONE_MONTH, _("One month")),
),
default=NEVER)
refound_period = models.CharField(_("refound period"), max_length=16,
help_text=_("Period in which automatic refound will be performed on "
"service cancellation"),
choices=(
(NEVER, _("Never refound")),
(TEN_DAYS, _("Ten days")),
(ONE_MONTH, _("One month")),
(ALWAYS, _("Always refound")),
),
default=NEVER, blank=True)
# trial_period = models.CharField(_("trial period"), max_length=16, blank=True,
# help_text=_("Period in which no charge will be issued"),
# choices=(
# (NEVER, _("No trial")),
# (TEN_DAYS, _("Ten days")),
# (ONE_MONTH, _("One month")),
# ),
# default=NEVER)
# refound_period = models.CharField(_("refound period"), max_length=16,
# help_text=_("Period in which automatic refound will be performed on "
# "service cancellation"),
# choices=(
# (NEVER, _("Never refound")),
# (TEN_DAYS, _("Ten days")),
# (ONE_MONTH, _("One month")),
# (ALWAYS, _("Always refound")),
# ),
# default=NEVER, blank=True)
def __unicode__(self):
return self.description