Random fixes

This commit is contained in:
Marc Aymerich 2015-07-09 10:44:22 +00:00
parent 09025102bc
commit 8cb36619e3
8 changed files with 32 additions and 32 deletions

View File

@ -438,8 +438,6 @@ serailzer self.instance on create.
# Automatically mark as paid transactions with 0 or prevent its creation? # Automatically mark as paid transactions with 0 or prevent its creation?
# Confirmation steps on amend and other billing actions
@register.filter @register.filter
def comma(value): def comma(value):
@ -449,5 +447,3 @@ def comma(value):
return ','.join((left, right)) return ','.join((left, right))
return value return value
# db_index on date_hierarchy

View File

@ -70,7 +70,7 @@ def action_with_confirmation(action_name=None, extra_context={},
context = { context = {
'title': _("Are you sure?"), 'title': _("Are you sure?"),
'content_message': _("Are you sure you want to {action} the selected {item}?").format( 'content_message': _("Are you sure you want to {action} the selected {item}?").format(
action=action_name, item=objects_name), action=action_name, item=objects_name),
'action_name': action_name.capitalize(), 'action_name': action_name.capitalize(),
'action_value': action_value, 'action_value': action_value,
'queryset': queryset, 'queryset': queryset,

View File

@ -44,22 +44,20 @@ class ChangeListDefaultFilter(object):
if hasattr(response, 'context_data') and 'cl' in response.context_data: if hasattr(response, 'context_data') and 'cl' in response.context_data:
response.context_data['cl'].default_changelist_filters = defaults response.context_data['cl'].default_changelist_filters = defaults
return response return response
# defaults = []
# querystring = request.META['QUERY_STRING']
defaults = [] # redirect = False
querystring = request.META['QUERY_STRING'] # for field, value in self.default_changelist_filters:
redirect = False # if field not in queryseting:
for field, value in self.default_changelist_filters: # redirect = True
if field not in queryseting: # querystring[field] = value
redirect = True # if redirect:
querystring[field] = value # raise
if redirect: # if not request.META.get('HTTP_REFERER', '').startswith(request.build_absolute_uri()):
raise # querystring = '&'.join('%s=%s' % filed, value in querystring.items())
if not request.META.get('HTTP_REFERER', '').startswith(request.build_absolute_uri()): # from django.http import HttpResponseRedirect
querystring = '&'.join('%s=%s' % filed, value in querystring.items()) # return HttpResponseRedirect(request.path + '?%s' % querystring)
from django.http import HttpResponseRedirect # return super(ChangeListDefaultFilter, self).changelist_view(request, extra_context=extra_context)
return HttpResponseRedirect(request.path + '?%s' % querystring)
return super(ChangeListDefaultFilter, self).changelist_view(request, extra_context=extra_context)
class AtLeastOneRequiredInlineFormSet(BaseInlineFormSet): class AtLeastOneRequiredInlineFormSet(BaseInlineFormSet):

View File

@ -1,4 +1,5 @@
import datetime import datetime
import importlib
import inspect import inspect
from functools import wraps from functools import wraps
@ -8,7 +9,6 @@ from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse, NoReverseMatch from django.core.urlresolvers import reverse, NoReverseMatch
from django.db import models from django.db import models
from django.shortcuts import redirect from django.shortcuts import redirect
import importlib
from django.utils.html import escape from django.utils.html import escape
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe

View File

@ -331,7 +331,9 @@ class BillAdmin(AccountAdminMixin, ExtendedModelAdmin):
(F('lines__subtotal') + Coalesce(F('lines__sublines__total'), 0)) * (1+F('lines__tax')/100) (F('lines__subtotal') + Coalesce(F('lines__sublines__total'), 0)) * (1+F('lines__tax')/100)
), ),
) )
qs = qs.prefetch_related(Prefetch('amends', queryset=Bill.objects.filter(is_open=False), to_attr='closed_amends')) qs = qs.prefetch_related(
Prefetch('amends', queryset=Bill.objects.filter(is_open=False), to_attr='closed_amends')
)
return qs return qs
def change_view(self, request, object_id, **kwargs): def change_view(self, request, object_id, **kwargs):

View File

@ -62,10 +62,10 @@ class OrderQuerySet(models.QuerySet):
conflictive = self.filter(service__metric='') conflictive = self.filter(service__metric='')
conflictive = conflictive.exclude(service__billing_period=Service.NEVER) conflictive = conflictive.exclude(service__billing_period=Service.NEVER)
# Exclude rates null or all rates with quantity 0 # Exclude rates null or all rates with quantity 0
conflictive = conflictive.annotate(quantity_sum=Sum('service__rates__quantity')).exclude(quantity_sum=0) conflictive = conflictive.annotate(quantity_sum=Sum('service__rates__quantity'))
conflictive = conflictive.select_related('service').distinct().group_by('account_id', 'service') conflictive = conflictive.exclude(quantity_sum=0).select_related('service').distinct()
qs = Q() qs = Q()
for account_id, services in conflictive.items(): for account_id, services in conflictive.group_by('account_id', 'service').items():
for service, orders in services.items(): for service, orders in services.items():
ini = datetime.date.max ini = datetime.date.max
end = datetime.date.min end = datetime.date.min
@ -137,7 +137,8 @@ class Order(models.Model):
else: else:
services = [service] services = [service]
for service in services: for service in services:
orders = Order.objects.by_object(instance, service=service).select_related('service').active() orders = Order.objects.by_object(instance, service=service)
orders = orders.select_related('service').active()
if service.handler.matches(instance): if service.handler.matches(instance):
if not orders: if not orders:
account_id = getattr(instance, 'account_id', instance.pk) account_id = getattr(instance, 'account_id', instance.pk)

View File

@ -66,7 +66,10 @@ class TransactionQuerySet(models.QuerySet):
source = kwargs.get('source') source = kwargs.get('source')
if source is None or not hasattr(source.method_class, 'process'): if source is None or not hasattr(source.method_class, 'process'):
# Manual payments don't need processing # Manual payments don't need processing
kwargs['state']=self.model.WAITTING_EXECUTION kwargs['state'] = self.model.WAITTING_EXECUTION
amount = kwargs.get('amount')
if amount == 0:
kwargs['state'] = self.model.SECURED
return super(TransactionQuerySet, self).create(**kwargs) return super(TransactionQuerySet, self).create(**kwargs)
def secured(self): def secured(self):
@ -100,8 +103,8 @@ class Transaction(models.Model):
related_name='transactions') related_name='transactions')
source = models.ForeignKey(PaymentSource, null=True, blank=True, source = models.ForeignKey(PaymentSource, null=True, blank=True,
verbose_name=_("source"), related_name='transactions') verbose_name=_("source"), related_name='transactions')
process = models.ForeignKey('payments.TransactionProcess', null=True, on_delete=models.SET_NULL, process = models.ForeignKey('payments.TransactionProcess', null=True, blank=True,
blank=True, verbose_name=_("process"), related_name='transactions') on_delete=models.SET_NULL, verbose_name=_("process"), related_name='transactions')
state = models.CharField(_("state"), max_length=32, choices=STATES, state = models.CharField(_("state"), max_length=32, choices=STATES,
default=WAITTING_PROCESSING) default=WAITTING_PROCESSING)
amount = models.DecimalField(_("amount"), max_digits=12, decimal_places=2) amount = models.DecimalField(_("amount"), max_digits=12, decimal_places=2)

View File

@ -101,8 +101,9 @@ class PHPApp(AppType):
init_vars['disable_functions'] = ','.join(disable_functions) init_vars['disable_functions'] = ','.join(disable_functions)
# Process timeout # Process timeout
if timeout: if timeout:
timeout = max(settings.WEBAPPS_PYTHON_DEFAULT_TIMEOUT, int(timeout))
# Give a little slack here # Give a little slack here
timeout = str(int(timeout)-2) timeout = str(timeout-2)
init_vars['max_execution_time'] = timeout init_vars['max_execution_time'] = timeout
# Custom error log # Custom error log
if self.PHP_ERROR_LOG_PATH and 'error_log' not in init_vars: if self.PHP_ERROR_LOG_PATH and 'error_log' not in init_vars:
@ -147,4 +148,3 @@ class PHPApp(AppType):
def get_php_version_number(self): def get_php_version_number(self):
php_version = self.get_php_version() php_version = self.get_php_version()
return utils.extract_version_number(php_version) return utils.extract_version_number(php_version)