Improvements on billing

This commit is contained in:
Marc Aymerich 2015-07-08 13:29:29 +00:00
parent 41163b5e52
commit a364f88452
5 changed files with 40 additions and 13 deletions

17
TODO.md
View File

@ -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)

View File

@ -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('<a href="{url}">{num}</a>'.format(url=url, num=amend.number))
return '<br>'.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

View File

@ -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)

View File

@ -49,9 +49,9 @@
<td class="item column-billcontant">{{ bill.buyer.get_name }}</td>
<td class="item column-date">{{ bill.closed_on|date }}</td>
{% with base=bill.compute_base total=bill.compute_total %}
<td class="item column-base">{{ base }} &{{ currency }};</td>
<td class="item column-vat">{{ total|sub:base }} &{{ currency }};</td>
<td class="item column-total">{{ total }} &{{ currency }};</td>
<td class="item column-base">{{ base }}</td>
<td class="item column-vat">{{ total|sub:base }}</td>
<td class="item column-total">{{ total }}</td>
{% endwith %}
</tr>
{% endfor %}

View File

@ -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'])