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"), { (_("Pricing options"), {
'classes': ('wide',), 'classes': ('wide',),
'fields': ('metric', 'pricing_period', 'rate_algorithm', 'fields': ('metric', 'pricing_period', 'rate_algorithm',
'orders_effect', 'on_cancel', 'payment_style', 'on_cancel', 'payment_style',
'trial_period', 'refound_period', 'tax', 'nominal_price') 'tax', 'nominal_price')
}), }),
) )
inlines = [RateInline] inlines = [RateInline]

View file

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

View file

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