From f6045869acad9c521bcead0539a5f86240c13aa1 Mon Sep 17 00:00:00 2001 From: Marc Date: Thu, 11 Sep 2014 14:00:20 +0000 Subject: [PATCH] Added support for ProForma bills --- orchestra/apps/bills/admin.py | 21 +++---- orchestra/apps/bills/filters.py | 2 +- .../migrations/0004_auto_20140911_1234.py | 19 ++++++ .../migrations/0005_auto_20140911_1234.py | 19 ++++++ .../migrations/0006_auto_20140911_1238.py | 59 +++++++++++++++++ orchestra/apps/bills/models.py | 38 +++-------- orchestra/apps/bills/settings.py | 3 +- .../bills/microspective-proforma.html | 9 +++ .../bills/templates/bills/microspective.html | 2 +- orchestra/apps/orders/actions.py | 9 ++- orchestra/apps/orders/billing.py | 63 +++++++++++-------- orchestra/apps/orders/forms.py | 8 ++- orchestra/apps/orders/models.py | 2 +- .../orders/order/bill_selected_options.html | 4 +- 14 files changed, 176 insertions(+), 82 deletions(-) create mode 100644 orchestra/apps/bills/migrations/0004_auto_20140911_1234.py create mode 100644 orchestra/apps/bills/migrations/0005_auto_20140911_1234.py create mode 100644 orchestra/apps/bills/migrations/0006_auto_20140911_1238.py create mode 100644 orchestra/apps/bills/templates/bills/microspective-proforma.html diff --git a/orchestra/apps/bills/admin.py b/orchestra/apps/bills/admin.py index 97a03e09..13ea7da9 100644 --- a/orchestra/apps/bills/admin.py +++ b/orchestra/apps/bills/admin.py @@ -13,8 +13,8 @@ from orchestra.apps.accounts.admin import AccountAdminMixin from . import settings from .actions import download_bills, view_bill, close_bills, send_bills from .filters import BillTypeListFilter -from .models import (Bill, Invoice, AmendmentInvoice, Fee, AmendmentFee, Budget, - BillLine, BudgetLine) +from .models import (Bill, Invoice, AmendmentInvoice, Fee, AmendmentFee, ProForma, + BillLine) class BillLineInline(admin.TabularInline): @@ -46,11 +46,6 @@ class BillLineInline(admin.TabularInline): return super(BillLineInline, self).formfield_for_dbfield(db_field, **kwargs) -class BudgetLineInline(BillLineInline): - model = Budget - fields = ('description', 'rate', 'amount', 'tax', 'total') - - class BillAdmin(AccountAdminMixin, ExtendedModelAdmin): list_display = ( 'number', 'status', 'type_link', 'account_link', 'created_on_display', @@ -77,8 +72,8 @@ class BillAdmin(AccountAdminMixin, ExtendedModelAdmin): created_on_display = admin_date('created_on') def num_lines(self, bill): - return bill.billlines__count - num_lines.admin_order_field = 'billlines__count' + return bill.lines__count + num_lines.admin_order_field = 'lines__count' num_lines.short_description = _("lines") def display_total(self, bill): @@ -120,8 +115,6 @@ class BillAdmin(AccountAdminMixin, ExtendedModelAdmin): return [action for action in actions if action.__name__ not in discard] def get_inline_instances(self, request, obj=None): - if self.model is Budget: - self.inlines = [BudgetLineInline] # Make parent object available for inline.has_add_permission() request.__bill__ = obj return super(BillAdmin, self).get_inline_instances(request, obj=obj) @@ -136,8 +129,8 @@ class BillAdmin(AccountAdminMixin, ExtendedModelAdmin): def get_queryset(self, request): qs = super(BillAdmin, self).get_queryset(request) - qs = qs.annotate(models.Count('billlines')) - qs = qs.prefetch_related('billlines', 'billlines__sublines') + qs = qs.annotate(models.Count('lines')) + qs = qs.prefetch_related('lines', 'lines__sublines') return qs # def change_view(self, request, object_id, **kwargs): @@ -154,4 +147,4 @@ admin.site.register(Invoice, BillAdmin) admin.site.register(AmendmentInvoice, BillAdmin) admin.site.register(Fee, BillAdmin) admin.site.register(AmendmentFee, BillAdmin) -admin.site.register(Budget, BillAdmin) +admin.site.register(ProForma, BillAdmin) diff --git a/orchestra/apps/bills/filters.py b/orchestra/apps/bills/filters.py index 4d52cfa8..2e8c89b1 100644 --- a/orchestra/apps/bills/filters.py +++ b/orchestra/apps/bills/filters.py @@ -19,7 +19,7 @@ class BillTypeListFilter(SimpleListFilter): ('amendmentinvoice', _("Amendment invoice")), ('fee', _("Fee")), ('fee', _("Amendment fee")), - ('budget', _("Budget")), + ('proforma', _("Pro-forma")), ) diff --git a/orchestra/apps/bills/migrations/0004_auto_20140911_1234.py b/orchestra/apps/bills/migrations/0004_auto_20140911_1234.py new file mode 100644 index 00000000..ae41b309 --- /dev/null +++ b/orchestra/apps/bills/migrations/0004_auto_20140911_1234.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('bills', '0003_bill_total'), + ] + + operations = [ + migrations.AlterField( + model_name='bill', + name='total', + field=models.DecimalField(default=0, max_digits=12, decimal_places=2), + ), + ] diff --git a/orchestra/apps/bills/migrations/0005_auto_20140911_1234.py b/orchestra/apps/bills/migrations/0005_auto_20140911_1234.py new file mode 100644 index 00000000..bff6b210 --- /dev/null +++ b/orchestra/apps/bills/migrations/0005_auto_20140911_1234.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('bills', '0004_auto_20140911_1234'), + ] + + operations = [ + migrations.RenameField( + model_name='billsubline', + old_name='bill_line', + new_name='line', + ), + ] diff --git a/orchestra/apps/bills/migrations/0006_auto_20140911_1238.py b/orchestra/apps/bills/migrations/0006_auto_20140911_1238.py new file mode 100644 index 00000000..018be2b3 --- /dev/null +++ b/orchestra/apps/bills/migrations/0006_auto_20140911_1238.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('bills', '0005_auto_20140911_1234'), + ] + + operations = [ + migrations.RemoveField( + model_name='budgetline', + name='bill', + ), + migrations.DeleteModel( + name='BudgetLine', + ), + migrations.DeleteModel( + name='Budget', + ), + migrations.CreateModel( + name='ProForma', + fields=[ + ], + options={ + 'proxy': True, + }, + bases=('bills.bill',), + ), + migrations.RemoveField( + model_name='billline', + name='auto', + ), + migrations.RemoveField( + model_name='billline', + name='order_billed_until', + ), + migrations.RemoveField( + model_name='billline', + name='order_id', + ), + migrations.RemoveField( + model_name='billline', + name='order_last_bill_date', + ), + migrations.AlterField( + model_name='bill', + name='type', + field=models.CharField(max_length=16, verbose_name='type', choices=[(b'INVOICE', 'Invoice'), (b'AMENDMENTINVOICE', 'Amendment invoice'), (b'FEE', 'Fee'), (b'AMENDMENTFEE', 'Amendment Fee'), (b'PROFORMA', 'Pro forma')]), + ), + migrations.AlterField( + model_name='billline', + name='bill', + field=models.ForeignKey(related_name=b'lines', verbose_name='bill', to='bills.Bill'), + ), + ] diff --git a/orchestra/apps/bills/models.py b/orchestra/apps/bills/models.py index 47f2b7d4..b29c8403 100644 --- a/orchestra/apps/bills/models.py +++ b/orchestra/apps/bills/models.py @@ -43,7 +43,7 @@ class Bill(models.Model): ('AMENDMENTINVOICE', _("Amendment invoice")), ('FEE', _("Fee")), ('AMENDMENTFEE', _("Amendment Fee")), - ('BUDGET', _("Budget")), + ('PROFORMA', _("Pro forma")), ) number = models.CharField(_("number"), max_length=16, unique=True, @@ -74,10 +74,6 @@ class Bill(models.Model): def buyer(self): return self.account.invoicecontact - @property - def lines(self): - return self.billlines - @classmethod def get_class_type(cls): return cls.__name__.upper() @@ -210,28 +206,22 @@ class AmendmentFee(Bill): proxy = True -class Budget(Bill): +class ProForma(Bill): class Meta: proxy = True - - @property - def lines(self): - return self.budgetlines -class BaseBillLine(models.Model): +class BillLine(models.Model): """ Base model for bill item representation """ - bill = models.ForeignKey(Bill, verbose_name=_("bill"), - related_name='%(class)ss') + bill = models.ForeignKey(Bill, verbose_name=_("bill"), related_name='lines') description = models.CharField(_("description"), max_length=256) rate = models.DecimalField(_("rate"), blank=True, null=True, max_digits=12, decimal_places=2) amount = models.DecimalField(_("amount"), max_digits=12, decimal_places=2) total = models.DecimalField(_("total"), max_digits=12, decimal_places=2) tax = models.PositiveIntegerField(_("tax")) - - class Meta: - abstract = True + amended_line = models.ForeignKey('self', verbose_name=_("amended line"), + related_name='amendment_lines', null=True, blank=True) def __unicode__(self): return "#%i" % self.number @@ -241,19 +231,6 @@ class BaseBillLine(models.Model): lines = type(self).objects.filter(bill=self.bill_id) return lines.filter(id__lte=self.id).order_by('id').count() - -class BudgetLine(BaseBillLine): - pass - - -class BillLine(BaseBillLine): - order_id = models.PositiveIntegerField(blank=True, null=True) - order_last_bill_date = models.DateTimeField(null=True) - order_billed_until = models.DateTimeField(null=True) - auto = models.BooleanField(default=False) - amended_line = models.ForeignKey('self', verbose_name=_("amended line"), - related_name='amendment_lines', null=True, blank=True) - def get_total(self): """ Computes subline discounts """ subtotal = self.total @@ -271,7 +248,7 @@ class BillLine(BaseBillLine): class BillSubline(models.Model): """ Subline used for describing an item discount """ - bill_line = models.ForeignKey(BillLine, verbose_name=_("bill line"), + line = models.ForeignKey(BillLine, verbose_name=_("bill line"), related_name='sublines') description = models.CharField(_("description"), max_length=256) total = models.DecimalField(max_digits=12, decimal_places=2) @@ -284,4 +261,5 @@ class BillSubline(models.Model): self.line.bill.total = self.line.bill.get_total() self.line.bill.save() + accounts.register(Bill) diff --git a/orchestra/apps/bills/settings.py b/orchestra/apps/bills/settings.py index 7649405f..ac590005 100644 --- a/orchestra/apps/bills/settings.py +++ b/orchestra/apps/bills/settings.py @@ -11,13 +11,14 @@ BILLS_FEE_NUMBER_PREFIX = getattr(settings, 'BILLS_FEE_NUMBER_PREFIX', 'F') BILLS_AMENDMENT_FEE_NUMBER_PREFIX = getattr(settings, 'BILLS_AMENDMENT_FEE_NUMBER_PREFIX', 'B') -BILLS_BUDGET_NUMBER_PREFIX = getattr(settings, 'BILLS_BUDGET_NUMBER_PREFIX', 'Q') +BILLS_PROFORMA_NUMBER_PREFIX = getattr(settings, 'BILLS_PROFORMA_NUMBER_PREFIX', 'P') BILLS_DEFAULT_TEMPLATE = getattr(settings, 'BILLS_DEFAULT_TEMPLATE', 'bills/microspective.html') BILLS_FEE_TEMPLATE = getattr(settings, 'BILLS_FEE_TEMPLATE', 'bills/microspective-fee.html') +BILLS_PROFORMA_TEMPLATE = getattr(settings, 'BILLS_PROFORMA_TEMPLATE', 'bills/microspective-proforma.html') diff --git a/orchestra/apps/bills/templates/bills/microspective-proforma.html b/orchestra/apps/bills/templates/bills/microspective-proforma.html new file mode 100644 index 00000000..8efbfbd3 --- /dev/null +++ b/orchestra/apps/bills/templates/bills/microspective-proforma.html @@ -0,0 +1,9 @@ +{% extends 'bills/microspective.html' %} + +{% block head %} + +{% endblock %} diff --git a/orchestra/apps/bills/templates/bills/microspective.html b/orchestra/apps/bills/templates/bills/microspective.html index 70be3191..a2c4f776 100644 --- a/orchestra/apps/bills/templates/bills/microspective.html +++ b/orchestra/apps/bills/templates/bills/microspective.html @@ -14,7 +14,7 @@ {% block header %} - {% for obj in selected_related_objects %} - - {% endfor %} {% for obj in queryset %} {% endfor %}