From 4e3105194c8f37272e2b55a57e5a988942dd4e95 Mon Sep 17 00:00:00 2001
From: Marc
Please select a payment source for the selected bills"), + 'action_name': 'Close bills', 'action_value': 'close_bills', - 'deletable_objects': queryset, + 'display_objects': [], 'queryset': queryset, 'opts': opts, 'app_label': opts.app_label, 'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME, 'formset': formset, } - # TODO use generic confirmation template - return render(request, 'admin/bills/close_confirmation.html', context) + return render(request, 'admin/orchestra/generic_confirmation.html', context) close_bills.verbose_name = _("Close") close_bills.url_name = 'close' diff --git a/orchestra/apps/bills/admin.py b/orchestra/apps/bills/admin.py index a86064ba..9bf70ac7 100644 --- a/orchestra/apps/bills/admin.py +++ b/orchestra/apps/bills/admin.py @@ -51,7 +51,6 @@ class BudgetLineInline(admin.TabularInline): fields = ('description', 'rate', 'amount', 'tax', 'total') -# TODO hide raw when status = oPen class BillAdmin(AccountAdminMixin, ExtendedModelAdmin): list_display = ( 'number', 'status', 'type_link', 'account_link', 'created_on_display', @@ -83,9 +82,10 @@ class BillAdmin(AccountAdminMixin, ExtendedModelAdmin): num_lines.short_description = _("lines") def display_total(self, bill): - return "%s &%s;" % (bill.get_total(), settings.BILLS_CURRENCY.lower()) + return "%s &%s;" % (bill.total, settings.BILLS_CURRENCY.lower()) display_total.allow_tags = True display_total.short_description = _("total") + display_total.admin_order_field = 'total' def type_link(self, bill): bill_type = bill.type.lower() @@ -101,6 +101,12 @@ class BillAdmin(AccountAdminMixin, ExtendedModelAdmin): fields += self.add_fields return fields + def get_fieldsets(self, request, obj=None): + fieldsets = super(BillAdmin, self).get_fieldsets(request, obj=obj) + if obj and obj.status == obj.OPEN: + fieldsets = (fieldsets[0],) + return fieldsets + def get_change_view_actions(self, obj=None): actions = super(BillAdmin, self).get_change_view_actions(obj) discard = [] diff --git a/orchestra/apps/bills/forms.py b/orchestra/apps/bills/forms.py index 840e034f..599c642a 100644 --- a/orchestra/apps/bills/forms.py +++ b/orchestra/apps/bills/forms.py @@ -26,7 +26,7 @@ class SelectSourceForm(forms.ModelForm): bill = kwargs.get('instance') if bill: sources = bill.account.paymentsources.filter(is_active=True) - recharge = bool(bill.get_total() < 0) + recharge = bool(bill.total < 0) choices = [(None, '-----------')] for source in sources: if not recharge or source.method_class().allow_recharge: diff --git a/orchestra/apps/bills/migrations/0003_bill_total.py b/orchestra/apps/bills/migrations/0003_bill_total.py new file mode 100644 index 00000000..6f51c303 --- /dev/null +++ b/orchestra/apps/bills/migrations/0003_bill_total.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('bills', '0002_bill_closed_on'), + ] + + operations = [ + migrations.AddField( + model_name='bill', + name='total', + field=models.DecimalField(default=10, max_digits=12, decimal_places=2), + preserve_default=False, + ), + ] diff --git a/orchestra/apps/bills/models.py b/orchestra/apps/bills/models.py index 2d2f9480..b3f0b9d6 100644 --- a/orchestra/apps/bills/models.py +++ b/orchestra/apps/bills/models.py @@ -57,10 +57,8 @@ class Bill(models.Model): closed_on = models.DateTimeField(_("closed on"), blank=True, null=True) due_on = models.DateField(_("due on"), null=True, blank=True) last_modified_on = models.DateTimeField(_("last modified on"), auto_now=True) - #base = models.DecimalField(max_digits=12, decimal_places=2) - #tax = models.DecimalField(max_digits=12, decimal_places=2) + total = models.DecimalField(max_digits=12, decimal_places=2) comments = models.TextField(_("comments"), blank=True) - # TODO rename to HTML-agnostic term like.. RAW ? html = models.TextField(_("HTML"), blank=True) objects = BillManager() @@ -121,10 +119,9 @@ class Bill(models.Model): payment = self.account.paymentsources.get_default() if not self.due_on: self.due_on = self.get_due_date(payment=payment) + self.total = self.get_total() self.html = self.render(payment=payment) - self.transactions.create( - bill=self, source=payment, amount=self.get_total() - ) + self.transactions.create(bill=self, source=payment, amount=self.total) self.closed_on = timezone.now() self.status = self.CLOSED self.save() @@ -173,6 +170,8 @@ class Bill(models.Model): def save(self, *args, **kwargs): if not self.type: self.type = self.get_type() + if self.status == self.OPEN: + self.total = self.get_total() if not self.number or (self.number.startswith('O') and self.status != self.OPEN): self.set_number() super(Bill, self).save(*args, **kwargs) @@ -190,7 +189,6 @@ class Bill(models.Model): @cached def get_total(self): - # TODO self.total = self.get_total on self.save() total = 0 for tax, subtotal in self.get_subtotals().iteritems(): subtotal, taxes = subtotal diff --git a/orchestra/apps/bills/templates/admin/bills/close_confirmation.html b/orchestra/apps/bills/templates/admin/bills/close_confirmation.html deleted file mode 100644 index 3dd3dd57..00000000 --- a/orchestra/apps/bills/templates/admin/bills/close_confirmation.html +++ /dev/null @@ -1,37 +0,0 @@ -{% extends "admin/base_site.html" %} -{% load i18n l10n staticfiles admin_urls %} - -{% block extrastyle %} -{{ block.super }} - - -{% endblock %} - - -{% block breadcrumbs %} -{% endblock %} - - -{% block content %} -
Once a bill is closed it can not be further modified.
-Please select a payment source for the selected bills
- -{% endblock %} - - diff --git a/orchestra/apps/domains/admin.py b/orchestra/apps/domains/admin.py index 233250c1..6691d7e9 100644 --- a/orchestra/apps/domains/admin.py +++ b/orchestra/apps/domains/admin.py @@ -112,7 +112,7 @@ class DomainAdmin(ChangeListDefaultFilter, AccountAdminMixin, ExtendedModelAdmin def get_queryset(self, request): """ Order by structured name and imporve performance """ qs = super(DomainAdmin, self).get_queryset(request) - qs = qs.select_related('top', 'account__user') + qs = qs.select_related('top') # qs = qs.select_related('top') # For some reason if we do this we know for sure that join table will be called T4 __ = str(qs.query) diff --git a/orchestra/apps/payments/admin.py b/orchestra/apps/payments/admin.py index 8303c2fe..b86abadf 100644 --- a/orchestra/apps/payments/admin.py +++ b/orchestra/apps/payments/admin.py @@ -5,7 +5,7 @@ from django.core.urlresolvers import reverse from django.shortcuts import render, redirect from django.utils.translation import ugettext_lazy as _ -from orchestra.admin.utils import admin_colored, admin_link +from orchestra.admin.utils import admin_colored, admin_link, wrap_admin_view from orchestra.apps.accounts.admin import AccountAdminMixin from .actions import process_transactions @@ -82,9 +82,8 @@ class PaymentSourceAdmin(AccountAdminMixin, admin.ModelAdmin): opts = self.model._meta info = opts.app_label, opts.model_name select_urls = patterns("", - # TODO wrap for authentication url("/select-method/$", - self.select_method_view, + wrap_admin_view(self, self.select_method_view), name='%s_%s_select_method' % info), ) return select_urls + urls diff --git a/orchestra/apps/payments/templates/admin/payments/payment_source/select_method.html b/orchestra/apps/payments/templates/admin/payments/payment_source/select_method.html deleted file mode 100644 index 0ca0e702..00000000 --- a/orchestra/apps/payments/templates/admin/payments/payment_source/select_method.html +++ /dev/null @@ -1,28 +0,0 @@ -{% extends "admin/base_site.html" %} -{% load i18n l10n staticfiles admin_urls %} - -{% block extrastyle %} -{{ block.super }} - -{% endblock %} - - -{% block breadcrumbs %} -TODO -{% endblock %} - - -{% block content %} -