From a364f88452b7db3ceb08de33aa2c889b195ec9c0 Mon Sep 17 00:00:00 2001 From: Marc Aymerich Date: Wed, 8 Jul 2015 13:29:29 +0000 Subject: [PATCH] Improvements on billing --- TODO.md | 17 +++++++++++++ orchestra/contrib/bills/admin.py | 24 ++++++++++++++----- orchestra/contrib/bills/filters.py | 5 ++-- .../bills/templates/admin/bills/report.html | 6 ++--- orchestra/contrib/payments/models.py | 1 - 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/TODO.md b/TODO.md index 951032e7..740223b6 100644 --- a/TODO.md +++ b/TODO.md @@ -434,3 +434,20 @@ serailzer self.instance on create. * backendLog store method and language... and use it for display_script with correct lexer # process monitor data to represent state, or maybe create new resource datas when period expires? + + +# Automatically mark as paid transactions with 0 or prevent its creation? + +# Confirmation steps on amend and other billing actions + + +@register.filter +def comma(value): + value = str(value) + if '.' in value: + left, right = str(value).split('.') + return ','.join((left, right)) + return value + + +# Close, send + download admin action for bills (with confirmation) diff --git a/orchestra/contrib/bills/admin.py b/orchestra/contrib/bills/admin.py index 10301e09..67d10c02 100644 --- a/orchestra/contrib/bills/admin.py +++ b/orchestra/contrib/bills/admin.py @@ -195,8 +195,8 @@ class BillAdmin(AccountAdminMixin, ExtendedModelAdmin): change_list_template = 'admin/bills/change_list.html' fieldsets = ( (None, { - 'fields': ('number', 'type', 'amend_of_link', 'account_link', 'display_total', - 'display_payment_state', 'is_sent', 'due_on', 'comments'), + 'fields': ['number', 'type', 'amend_of_link', 'account_link', 'display_total', + 'display_payment_state', 'is_sent', 'due_on', 'comments'], }), (_("Raw"), { 'classes': ('collapse',), @@ -213,13 +213,23 @@ class BillAdmin(AccountAdminMixin, ExtendedModelAdmin): actions.manage_lines, actions.download_bills, actions.close_bills, actions.send_bills, actions.amend_bills, actions.report ] - change_readonly_fields = ('account_link', 'type', 'is_open', 'amend_of_link') + change_readonly_fields = ('account_link', 'type', 'is_open', 'amend_of_link', 'amend_links') readonly_fields = ('number', 'display_total', 'is_sent', 'display_payment_state') inlines = [BillLineInline, ClosedBillLineInline] + date_hierarchy = 'closed_on' created_on_display = admin_date('created_on', short_description=_("Created")) amend_of_link = admin_link('amend_of') + def amend_links(self, bill): + links = [] + for amend in bill.amends.all(): + url = reverse('admin:bills_bill_change', args=(amend.id,)) + links.append('{num}'.format(url=url, num=amend.number)) + return '
'.join(links) + amend_links.short_description = _("Amends") + amend_links.allow_tags = True + def num_lines(self, bill): return bill.lines__count num_lines.admin_order_field = 'lines__count' @@ -279,9 +289,11 @@ class BillAdmin(AccountAdminMixin, ExtendedModelAdmin): def get_fieldsets(self, request, obj=None): fieldsets = super(BillAdmin, self).get_fieldsets(request, obj) if obj: -# if obj.amend_of_id: -# fieldsets = list(fieldsets) -# fieldsets[0][1]['fields'] = fieldsets[0][1]['fields'] + ('amend_of_link',) + # Switches between amend_of_link and amend_links fields + if obj.amend_of_id: + fieldsets[0][1]['fields'][2] = 'amend_of_link' + else: + fieldsets[0][1]['fields'][2] = 'amend_links' if obj.is_open: fieldsets = (fieldsets[0],) return fieldsets diff --git a/orchestra/contrib/bills/filters.py b/orchestra/contrib/bills/filters.py index dae95794..cd706656 100644 --- a/orchestra/contrib/bills/filters.py +++ b/orchestra/contrib/bills/filters.py @@ -20,10 +20,10 @@ class BillTypeListFilter(SimpleListFilter): return ( ('bill', _("All")), ('invoice', _("Invoice")), - ('amendmentinvoice', _("Amendment invoice")), ('fee', _("Fee")), - ('amendmentfee', _("Amendment fee")), ('proforma', _("Pro-forma")), + ('amendmentfee', _("Amendment fee")), + ('amendmentinvoice', _("Amendment invoice")), ) def queryset(self, request, queryset): @@ -152,4 +152,3 @@ class AmendedListFilter(SimpleListFilter): return queryset.filter(id__in=amended_ids) else: return queryset.exclude(id__in=amended_ids) - diff --git a/orchestra/contrib/bills/templates/admin/bills/report.html b/orchestra/contrib/bills/templates/admin/bills/report.html index 7cb63a83..61d74426 100644 --- a/orchestra/contrib/bills/templates/admin/bills/report.html +++ b/orchestra/contrib/bills/templates/admin/bills/report.html @@ -49,9 +49,9 @@ {{ bill.buyer.get_name }} {{ bill.closed_on|date }} {% with base=bill.compute_base total=bill.compute_total %} - {{ base }} &{{ currency }}; - {{ total|sub:base }} &{{ currency }}; - {{ total }} &{{ currency }}; + {{ base }} + {{ total|sub:base }} + {{ total }} {% endwith %} {% endfor %} diff --git a/orchestra/contrib/payments/models.py b/orchestra/contrib/payments/models.py index dc012d5a..9a89303d 100644 --- a/orchestra/contrib/payments/models.py +++ b/orchestra/contrib/payments/models.py @@ -144,7 +144,6 @@ class Transaction(models.Model): self.save(update_fields=['state', 'modified_at']) def mark_as_rejected(self): - self.check_state(self.EXECUTED) self.state = self.REJECTED self.save(update_fields=['state', 'modified_at'])