Improvements on order billing
This commit is contained in:
parent
6533331461
commit
53b1391b1d
|
@ -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]
|
||||||
|
|
|
@ -192,13 +192,15 @@ 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)
|
||||||
|
|
||||||
|
rates = 'TODO'
|
||||||
|
if rates:
|
||||||
# Get pricing orders
|
# Get pricing orders
|
||||||
porders = related_orders.filter_pricing_orders(ini, end)
|
porders = related_orders.filter_pricing_orders(ini, end)
|
||||||
porders = set(orders).union(set(porders))
|
porders = set(orders).union(set(porders))
|
||||||
|
@ -214,6 +216,8 @@ class ServiceHandler(plugins.Plugin):
|
||||||
# TODO position +1?
|
# TODO position +1?
|
||||||
price = self.get_price(order, metric, position=position)
|
price = self.get_price(order, metric, position=position)
|
||||||
price *= size
|
price *= size
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
def compensate(self, givers, receivers):
|
def compensate(self, givers, receivers):
|
||||||
compensations = []
|
compensations = []
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue