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 * 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? # 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' change_list_template = 'admin/bills/change_list.html'
fieldsets = ( fieldsets = (
(None, { (None, {
'fields': ('number', 'type', 'amend_of_link', 'account_link', 'display_total', 'fields': ['number', 'type', 'amend_of_link', 'account_link', 'display_total',
'display_payment_state', 'is_sent', 'due_on', 'comments'), 'display_payment_state', 'is_sent', 'due_on', 'comments'],
}), }),
(_("Raw"), { (_("Raw"), {
'classes': ('collapse',), 'classes': ('collapse',),
@ -213,13 +213,23 @@ class BillAdmin(AccountAdminMixin, ExtendedModelAdmin):
actions.manage_lines, actions.download_bills, actions.close_bills, actions.send_bills, actions.manage_lines, actions.download_bills, actions.close_bills, actions.send_bills,
actions.amend_bills, actions.report 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') readonly_fields = ('number', 'display_total', 'is_sent', 'display_payment_state')
inlines = [BillLineInline, ClosedBillLineInline] inlines = [BillLineInline, ClosedBillLineInline]
date_hierarchy = 'closed_on'
created_on_display = admin_date('created_on', short_description=_("Created")) created_on_display = admin_date('created_on', short_description=_("Created"))
amend_of_link = admin_link('amend_of') 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): def num_lines(self, bill):
return bill.lines__count return bill.lines__count
num_lines.admin_order_field = 'lines__count' num_lines.admin_order_field = 'lines__count'
@ -279,9 +289,11 @@ class BillAdmin(AccountAdminMixin, ExtendedModelAdmin):
def get_fieldsets(self, request, obj=None): def get_fieldsets(self, request, obj=None):
fieldsets = super(BillAdmin, self).get_fieldsets(request, obj) fieldsets = super(BillAdmin, self).get_fieldsets(request, obj)
if obj: if obj:
# if obj.amend_of_id: # Switches between amend_of_link and amend_links fields
# fieldsets = list(fieldsets) if obj.amend_of_id:
# fieldsets[0][1]['fields'] = fieldsets[0][1]['fields'] + ('amend_of_link',) fieldsets[0][1]['fields'][2] = 'amend_of_link'
else:
fieldsets[0][1]['fields'][2] = 'amend_links'
if obj.is_open: if obj.is_open:
fieldsets = (fieldsets[0],) fieldsets = (fieldsets[0],)
return fieldsets return fieldsets

View file

@ -20,10 +20,10 @@ class BillTypeListFilter(SimpleListFilter):
return ( return (
('bill', _("All")), ('bill', _("All")),
('invoice', _("Invoice")), ('invoice', _("Invoice")),
('amendmentinvoice', _("Amendment invoice")),
('fee', _("Fee")), ('fee', _("Fee")),
('amendmentfee', _("Amendment fee")),
('proforma', _("Pro-forma")), ('proforma', _("Pro-forma")),
('amendmentfee', _("Amendment fee")),
('amendmentinvoice', _("Amendment invoice")),
) )
def queryset(self, request, queryset): def queryset(self, request, queryset):
@ -152,4 +152,3 @@ class AmendedListFilter(SimpleListFilter):
return queryset.filter(id__in=amended_ids) return queryset.filter(id__in=amended_ids)
else: else:
return queryset.exclude(id__in=amended_ids) 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-billcontant">{{ bill.buyer.get_name }}</td>
<td class="item column-date">{{ bill.closed_on|date }}</td> <td class="item column-date">{{ bill.closed_on|date }}</td>
{% with base=bill.compute_base total=bill.compute_total %} {% with base=bill.compute_base total=bill.compute_total %}
<td class="item column-base">{{ base }} &{{ currency }};</td> <td class="item column-base">{{ base }}</td>
<td class="item column-vat">{{ total|sub:base }} &{{ currency }};</td> <td class="item column-vat">{{ total|sub:base }}</td>
<td class="item column-total">{{ total }} &{{ currency }};</td> <td class="item column-total">{{ total }}</td>
{% endwith %} {% endwith %}
</tr> </tr>
{% endfor %} {% endfor %}

View file

@ -144,7 +144,6 @@ class Transaction(models.Model):
self.save(update_fields=['state', 'modified_at']) self.save(update_fields=['state', 'modified_at'])
def mark_as_rejected(self): def mark_as_rejected(self):
self.check_state(self.EXECUTED)
self.state = self.REJECTED self.state = self.REJECTED
self.save(update_fields=['state', 'modified_at']) self.save(update_fields=['state', 'modified_at'])