From 53b1391b1dd1ad153ee053d363dab9f09165539e Mon Sep 17 00:00:00 2001 From: Marc Date: Sun, 14 Sep 2014 22:00:00 +0000 Subject: [PATCH] Improvements on order billing --- orchestra/apps/orders/admin.py | 4 +- orchestra/apps/orders/handlers.py | 36 +++++++++------- orchestra/apps/orders/models.py | 72 +++++++++++++++---------------- 3 files changed, 56 insertions(+), 56 deletions(-) diff --git a/orchestra/apps/orders/admin.py b/orchestra/apps/orders/admin.py index 5a330400..15e8edc3 100644 --- a/orchestra/apps/orders/admin.py +++ b/orchestra/apps/orders/admin.py @@ -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] diff --git a/orchestra/apps/orders/handlers.py b/orchestra/apps/orders/handlers.py index 46879f1b..2e358b0f 100644 --- a/orchestra/apps/orders/handlers.py +++ b/orchestra/apps/orders/handlers.py @@ -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 = [] diff --git a/orchestra/apps/orders/models.py b/orchestra/apps/orders/models.py index ec5d887d..8041fbaf 100644 --- a/orchestra/apps/orders/models.py +++ b/orchestra/apps/orders/models.py @@ -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