From 450667c5135c2e933682d6b825da992a1f4bff2f Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Tue, 29 Sep 2015 11:01:51 +0300 Subject: Added Location field to Invoice --- servo/migrations/0032_auto_20150929_1101.py | 24 ++++++++++++++++++++++++ servo/models/invoices.py | 24 +++++++++++++++++++----- servo/views/device.py | 2 +- 3 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 servo/migrations/0032_auto_20150929_1101.py diff --git a/servo/migrations/0032_auto_20150929_1101.py b/servo/migrations/0032_auto_20150929_1101.py new file mode 100644 index 0000000..e7b17ec --- /dev/null +++ b/servo/migrations/0032_auto_20150929_1101.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('servo', '0031_auto_20150929_0010'), + ] + + operations = [ + migrations.AddField( + model_name='invoice', + name='location', + field=models.ForeignKey(blank=True, editable=False, to='servo.Location', null=True), + ), + migrations.AlterField( + model_name='invoice', + name='is_paid', + field=models.BooleanField(default=False, verbose_name='Paid'), + ), + ] diff --git a/servo/models/invoices.py b/servo/models/invoices.py index 7fa4287..8d5d8f2 100644 --- a/servo/models/invoices.py +++ b/servo/models/invoices.py @@ -8,8 +8,8 @@ from django.utils.translation import ugettext_lazy as _ from django.dispatch import receiver from django.db.models.signals import post_save -from servo import defaults -from servo.models import User, Customer, Order, ServiceOrderItem, AbstractOrderItem +from servo.models import (User, Customer, Order, Location, + AbstractOrderItem, ServiceOrderItem,) class Invoice(models.Model): @@ -32,9 +32,15 @@ class Invoice(models.Model): verbose_name=_("Payment Method") ) - is_paid = models.BooleanField(default=False, verbose_name=_("paid")) + is_paid = models.BooleanField(default=False, verbose_name=_("Paid")) paid_at = models.DateTimeField(null=True, editable=False) order = models.ForeignKey(Order, editable=False) + location = models.ForeignKey( + Location, + null=True, + blank=True, + editable=False + ) customer = models.ForeignKey( Customer, null=True, @@ -42,8 +48,8 @@ class Invoice(models.Model): on_delete=models.SET_NULL ) - # We remember the following the following so that the customer info - # on the invoice doesn't change if the customer is modified or deleted + # We remember the following so that the customer info on the invoice + # doesn't change if the customer is modified or deleted customer_name = models.CharField( max_length=255, default=_("Walk-in"), @@ -97,6 +103,9 @@ class Invoice(models.Model): return [x.get_method_display() for x in payments] def dispatch(self, products): + """ + Dispatches the products in this invoice from the inventory + """ for p in products: soi = ServiceOrderItem.objects.get(pk=p) InvoiceItem.from_soi(soi, self) @@ -109,6 +118,11 @@ class Invoice(models.Model): from django.core.urlresolvers import reverse return reverse("invoices-view_invoice", args=[self.pk]) + def save(self, *args, **kwargs): + if self.location is None: + self.location = self.order.location + return super(Invoice, self).save(*args, **kwargs) + class Meta: ordering = ('-id',) app_label = 'servo' diff --git a/servo/views/device.py b/servo/views/device.py index a955b1c..9babbd2 100644 --- a/servo/views/device.py +++ b/servo/views/device.py @@ -232,7 +232,7 @@ def diagnostics(request, pk): diagnostics = DiagnosticResults(diagnostics) return render(request, "devices/diagnostic_ios.html", locals()) return render(request, "devices/diagnostic_results.html", locals()) - except gsxws.GsxError, e: + except gsxws.GsxError as e: return render(request, "devices/diagnostic_error.html", {'error': e}) return render(request, "devices/diagnostics.html", locals()) -- cgit v1.2.3