aboutsummaryrefslogtreecommitdiffstats
path: root/servo
diff options
context:
space:
mode:
Diffstat (limited to 'servo')
-rw-r--r--servo/forms/__init__.py12
-rw-r--r--servo/forms/checkin.py4
-rw-r--r--servo/forms/notes.py2
-rw-r--r--servo/models/escalations.py3
-rw-r--r--servo/models/invoices.py16
-rw-r--r--servo/models/note.py17
-rw-r--r--servo/models/order.py24
-rw-r--r--servo/models/parts.py13
-rw-r--r--servo/models/purchases.py17
-rw-r--r--servo/models/repair.py8
-rw-r--r--servo/models/rules.py8
-rw-r--r--servo/models/shipments.py5
12 files changed, 76 insertions, 53 deletions
diff --git a/servo/forms/__init__.py b/servo/forms/__init__.py
index 0c8f2d5..243075b 100644
--- a/servo/forms/__init__.py
+++ b/servo/forms/__init__.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-from base import *
-from orders import *
-from notes import *
-from devices import *
-from product import *
-from repairs import *
+from .base import *
+from .orders import *
+from .notes import *
+from .devices import *
+from .product import *
+from .repairs import *
from .checkin import *
diff --git a/servo/forms/checkin.py b/servo/forms/checkin.py
index b3ed0d0..8cd19c4 100644
--- a/servo/forms/checkin.py
+++ b/servo/forms/checkin.py
@@ -8,7 +8,7 @@ from django.conf import settings
from django_countries import countries
from django.core.validators import RegexValidator
from django.utils.translation import ugettext_lazy as _
-from django.forms.extras.widgets import SelectDateWidget
+from django.forms import SelectDateWidget
from servo.validators import (apple_sn_validator,
phone_validator,
@@ -22,7 +22,7 @@ from servo.models import (Configuration, Device,
# Generate list of years for purchase date picker
y = date.today().year
-YEARS = [x + 1 for x in xrange(y - 10, y)]
+YEARS = [x + 1 for x in range(y - 10, y)]
def get_checkin_locations(user):
diff --git a/servo/forms/notes.py b/servo/forms/notes.py
index a5b0bb4..b6ce1af 100644
--- a/servo/forms/notes.py
+++ b/servo/forms/notes.py
@@ -2,7 +2,7 @@
import json
from django import forms
-from django.core.urlresolvers import reverse
+from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from servo.models import Note, Escalation, Template
diff --git a/servo/models/escalations.py b/servo/models/escalations.py
index 924c537..b42d8ca 100644
--- a/servo/models/escalations.py
+++ b/servo/models/escalations.py
@@ -23,6 +23,7 @@ class Escalation(models.Model):
)
gsx_account = models.ForeignKey(
GsxAccount,
+ on_delete=models.SET_NULL,
default=defaults.gsx_account,
verbose_name=_('GSX Account'),
)
@@ -40,7 +41,7 @@ class Escalation(models.Model):
)
submitted_at = models.DateTimeField(null=True)
updated_at = models.DateTimeField(auto_now=True)
- created_by = models.ForeignKey(User, editable=False, null=True)
+ created_by = models.ForeignKey(User, editable=False, null=True, on_delete=models.SET_NULL)
def is_submitted(self):
return self.submitted_at is not None
diff --git a/servo/models/invoices.py b/servo/models/invoices.py
index 2154377..cbcbd66 100644
--- a/servo/models/invoices.py
+++ b/servo/models/invoices.py
@@ -14,7 +14,7 @@ from servo.models import (User, Customer, Order, Location,
class Invoice(models.Model):
created_at = models.DateTimeField(editable=False, auto_now_add=True)
- created_by = models.ForeignKey(settings.AUTH_USER_MODEL, editable=False)
+ created_by = models.ForeignKey(settings.AUTH_USER_MODEL, editable=False, on_delete=models.SET_NULL)
PAYMENT_METHODS = (
(0, _("No Charge")),
@@ -34,12 +34,13 @@ class Invoice(models.Model):
is_paid = models.BooleanField(default=False, verbose_name=_("Paid"))
paid_at = models.DateTimeField(null=True, editable=False)
- order = models.ForeignKey(Order, editable=False)
+ order = models.ForeignKey(Order, editable=False, on_delete=models.PROTECT)
location = models.ForeignKey(
Location,
null=True,
blank=True,
- editable=False
+ editable=False,
+ on_delete=models.SET_NULL
)
customer = models.ForeignKey(
Customer,
@@ -115,7 +116,7 @@ class Invoice(models.Model):
soi.save()
def get_absolute_url(self):
- from django.core.urlresolvers import reverse
+ from django.urls import reverse
return reverse("invoices-view_invoice", args=[self.pk])
def save(self, *args, **kwargs):
@@ -135,7 +136,8 @@ class Invoice(models.Model):
class InvoiceItem(AbstractOrderItem):
- invoice = models.ForeignKey(Invoice)
+ """A line item on an invoice."""
+ invoice = models.ForeignKey(Invoice, on_delete=models.CASCADE)
price = models.DecimalField(
max_digits=8,
decimal_places=2,
@@ -168,7 +170,7 @@ class InvoiceItem(AbstractOrderItem):
class Payment(models.Model):
- invoice = models.ForeignKey(Invoice)
+ invoice = models.ForeignKey(Invoice, on_delete=models.CASCADE)
METHODS = (
(0, _("No Charge")),
(1, _("Cash")),
@@ -182,7 +184,7 @@ class Payment(models.Model):
default=METHODS[0][0],
verbose_name=_("Payment Method")
)
- created_by = models.ForeignKey(User)
+ created_by = models.ForeignKey(User, on_delete=models.SET_NULL)
created_at = models.DateTimeField(auto_now_add=True)
amount = models.DecimalField(max_digits=8, decimal_places=2)
diff --git a/servo/models/note.py b/servo/models/note.py
index 0bc4183..1e0e565 100644
--- a/servo/models/note.py
+++ b/servo/models/note.py
@@ -92,8 +92,8 @@ class Note(MPTTModel):
max_length=255,
verbose_name=_('To')
)
- customer = models.ForeignKey(Customer, null=True, blank=True)
- escalation = UnsavedForeignKey(Escalation, null=True, editable=False)
+ customer = models.ForeignKey(Customer, null=True, blank=True, on_delete=models.SET_NULL)
+ escalation = UnsavedForeignKey(Escalation, null=True, editable=False, on_delete=models.SET_NULL)
labels = models.ManyToManyField(Tag, blank=True, limit_choices_to={'type': 'note'})
events = GenericRelation(Event)
@@ -102,13 +102,14 @@ class Note(MPTTModel):
'self',
null=True,
blank=True,
- related_name='replies'
+ related_name='replies',
+ on_delete=models.CASCADE,
)
created_at = models.DateTimeField(auto_now_add=True, editable=False)
- created_by = models.ForeignKey(settings.AUTH_USER_MODEL, editable=False)
+ created_by = models.ForeignKey(settings.AUTH_USER_MODEL, editable=False, on_delete=models.SET_NULL)
sent_at = models.DateTimeField(null=True, editable=False)
- order = models.ForeignKey(Order, null=True, blank=True)
+ order = models.ForeignKey(Order, null=True, blank=True, on_delete=models.CASCADE)
is_reported = models.BooleanField(
default=False,
@@ -572,9 +573,9 @@ class Message(models.Model):
Keeping this separate from Note so that we can send and track
messages separately from Notes
"""
- note = models.ForeignKey(Note)
+ note = models.ForeignKey(Note, on_delete=models.CASCADE)
code = models.CharField(unique=True, max_length=36, default=defaults.uid)
- created_by = models.ForeignKey(User)
+ created_by = models.ForeignKey(User, on_delete=models.SET_NULL)
sender = models.CharField(max_length=128)
recipient = models.CharField(max_length=128)
body = models.TextField()
@@ -627,7 +628,7 @@ class Article(models.Model):
"""
GSX Communications article or a bit of local news
"""
- created_by = models.ForeignKey(User, null=True)
+ created_by = models.ForeignKey(User, null=True, on_delete=models.SET_NULL)
gsx_id = models.CharField(max_length=20, default='', editable=False)
date_created = models.DateField(editable=False)
date_published = models.DateField(null=True)
diff --git a/servo/models/order.py b/servo/models/order.py
index 9640029..980ae54 100644
--- a/servo/models/order.py
+++ b/servo/models/order.py
@@ -10,8 +10,8 @@ from django.utils.translation import ugettext_lazy as _
from django.contrib.postgres.fields import ArrayField
from django.contrib.contenttypes.fields import GenericRelation
+from django.urls import reverse
from django.dispatch import receiver
-from django.core.urlresolvers import reverse
from django.db.models.signals import pre_save, post_save, post_delete
from servo import defaults
@@ -898,7 +898,7 @@ class ServiceOrderItem(AbstractOrderItem):
"""
A product that has been added to a Service Order
"""
- order = models.ForeignKey(Order)
+ order = models.ForeignKey(Order, on_delete=models.CASCADE)
dispatched = models.BooleanField(
default=False,
@@ -919,6 +919,7 @@ class ServiceOrderItem(AbstractOrderItem):
settings.AUTH_USER_MODEL,
null=True,
editable=False,
+ on_delete=models.SET_NULL,
related_name='replaced_parts'
)
@@ -1037,20 +1038,22 @@ class OrderStatus(models.Model):
"""
The M/M statuses of an order
"""
- order = models.ForeignKey(Order)
- status = models.ForeignKey(Status)
+ order = models.ForeignKey(Order, on_delete=models.CASCADE)
+ status = models.ForeignKey(Status, on_delete=models.CASCADE)
started_at = models.DateTimeField(auto_now_add=True)
finished_at = models.DateTimeField(null=True)
started_by = models.ForeignKey(
settings.AUTH_USER_MODEL,
- related_name='+'
+ related_name='+',
+ on_delete=models.CASCADE,
)
finished_by = models.ForeignKey(
settings.AUTH_USER_MODEL,
null=True,
- related_name='+'
+ related_name='+',
+ on_delete=models.CASCADE,
)
green_limit = models.DateTimeField(null=True)
@@ -1128,8 +1131,9 @@ class OrderDevice(models.Model):
"""
A device attached to a service order
"""
- order = models.ForeignKey(Order)
- device = models.ForeignKey(Device)
+ order = models.ForeignKey(Order, on_delete=models.CASCADE)
+ device = models.ForeignKey(Device, on_delete=models.PROTECT)
+
should_report = models.BooleanField(default=True)
repeat_service = models.BooleanField(default=False)
repair_strategies = ArrayField(models.CharField(max_length=100),
@@ -1160,8 +1164,8 @@ class Accessory(models.Model):
"""
name = models.TextField()
qty = models.IntegerField(default=1)
- device = models.ForeignKey(Device)
- order = models.ForeignKey(Order)
+ device = models.ForeignKey(Device, on_delete=models.CASCADE)
+ order = models.ForeignKey(Order, on_delete=models.CASCADE)
def __unicode__(self):
return self.name
diff --git a/servo/models/parts.py b/servo/models/parts.py
index 1d38c24..e1e099d 100644
--- a/servo/models/parts.py
+++ b/servo/models/parts.py
@@ -68,9 +68,12 @@ class ServicePart(models.Model):
Stores the data necessary to connect our ServiceOrderItems
with the corresponding GSX parts
"""
- repair = models.ForeignKey("Repair", editable=False)
- order_item = models.ForeignKey(ServiceOrderItem, editable=False)
- purchase_order = models.ForeignKey(PurchaseOrder, null=True, editable=False)
+ repair = models.ForeignKey("Repair",
+ editable=False, on_delete=models.CASCADE)
+ order_item = models.ForeignKey(ServiceOrderItem,
+ editable=False, on_delete=models.CASCADE)
+ purchase_order = models.ForeignKey(PurchaseOrder,
+ null=True, editable=False, on_delete=models.SET_NULL)
comptia_code = models.CharField(
max_length=4,
@@ -133,7 +136,9 @@ class ServicePart(models.Model):
editable=False
)
- shipment = models.ForeignKey(Shipment, null=True)
+ shipment = models.ForeignKey(Shipment,
+ null=True,
+ on_delete=models.SET_NULL)
box_number = models.PositiveIntegerField(null=True)
return_label = models.FileField(
null=True,
diff --git a/servo/models/purchases.py b/servo/models/purchases.py
index 015e12c..f79bc6e 100644
--- a/servo/models/purchases.py
+++ b/servo/models/purchases.py
@@ -27,9 +27,10 @@ class PurchaseOrder(models.Model):
location = models.ForeignKey(
Location,
editable=False,
+ on_delete=models.SET_NULL,
help_text=_('The location from which this PO was created')
)
- sales_order = models.ForeignKey(Order, null=True, editable=False)
+ sales_order = models.ForeignKey(Order, null=True, editable=False, on_delete=models.SET_NULL)
reference = models.CharField(
blank=True,
default='',
@@ -43,7 +44,9 @@ class PurchaseOrder(models.Model):
verbose_name=_("Confirmation"),
)
- created_by = models.ForeignKey(settings.AUTH_USER_MODEL, editable=False)
+ created_by = models.ForeignKey(settings.AUTH_USER_MODEL,
+ editable=False,
+ on_delete=models.SET_NULL)
created_at = models.DateTimeField(auto_now_add=True, editable=False)
submitted_at = models.DateTimeField(null=True, editable=False)
@@ -189,7 +192,7 @@ class PurchaseOrder(models.Model):
class PurchaseOrderItem(AbstractOrderItem):
"""
- An item being purchased
+ A line item on a Purchase Order
"""
price = models.DecimalField(
max_digits=8,
@@ -201,6 +204,7 @@ class PurchaseOrderItem(AbstractOrderItem):
purchase_order = models.ForeignKey(
PurchaseOrder,
editable=False,
+ on_delete=models.CASCADE,
verbose_name=_("Purchase Order")
)
@@ -209,6 +213,7 @@ class PurchaseOrderItem(AbstractOrderItem):
Order,
null=True,
editable=False,
+ on_delete=models.SET_NULL,
)
sales_order_ref = models.CharField(
@@ -230,7 +235,8 @@ class PurchaseOrderItem(AbstractOrderItem):
)
# /end optimization
- order_item = models.ForeignKey(ServiceOrderItem, null=True, editable=False)
+ order_item = models.ForeignKey(ServiceOrderItem,
+ null=True, editable=False, on_delete=models.SET_NULL)
reference = models.CharField(default='', blank=True, max_length=128)
ordered_at = models.DateTimeField(null=True, editable=False)
@@ -246,7 +252,8 @@ class PurchaseOrderItem(AbstractOrderItem):
settings.AUTH_USER_MODEL,
null=True,
editable=False,
- related_name='+'
+ related_name='+',
+ on_delete=models.SET_NULL,
)
@classmethod
diff --git a/servo/models/repair.py b/servo/models/repair.py
index e817eb2..3568684 100644
--- a/servo/models/repair.py
+++ b/servo/models/repair.py
@@ -51,7 +51,7 @@ class Checklist(models.Model):
class ChecklistItem(models.Model):
- checklist = models.ForeignKey(Checklist)
+ checklist = models.ForeignKey(Checklist, on_delete=models.CASCADE)
title = models.CharField(max_length=255, verbose_name=_("Task"))
description = models.TextField(
blank=True,
@@ -74,11 +74,11 @@ class ChecklistItem(models.Model):
class ChecklistItemValue(models.Model):
- order = models.ForeignKey(Order)
- item = models.ForeignKey(ChecklistItem)
+ order = models.ForeignKey(Order, on_delete=models.CASCADE)
+ item = models.ForeignKey(ChecklistItem, on_delete=models.CASCADE)
checked_at = models.DateTimeField(auto_now_add=True)
- checked_by = models.ForeignKey(settings.AUTH_USER_MODEL)
+ checked_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
class Meta:
app_label = "servo"
diff --git a/servo/models/rules.py b/servo/models/rules.py
index 26fab03..14fc3bb 100644
--- a/servo/models/rules.py
+++ b/servo/models/rules.py
@@ -80,7 +80,7 @@ class Rule(ServoModel):
class Condition(ServoModel):
- rule = models.ForeignKey(Rule)
+ rule = models.ForeignKey(Rule, on_delete=models.CASCADE)
EVENT_MAP = {
'device_added': 'DEVICE',
@@ -118,7 +118,7 @@ class Condition(ServoModel):
class Action(ServoModel):
- rule = models.ForeignKey(Rule)
+ rule = models.ForeignKey(Rule, on_delete=models.CASCADE)
KEY_CHOICES = (
('SEND_SMS', _('Send SMS')),
@@ -156,9 +156,9 @@ class Action(ServoModel):
def process_event(sender, instance, created, **kwargs):
try:
condition = Condition.EVENT_MAP[instance.action]
- print condition
+ print(condition)
for r in Rule.objects.filter(condition__key=condition):
- print 'APPLYING %s' % condition
+ print('APPLYING %s' % condition)
r.apply(instance)
except KeyError:
return # no mapping for this event
diff --git a/servo/models/shipments.py b/servo/models/shipments.py
index 614c642..9f93927 100644
--- a/servo/models/shipments.py
+++ b/servo/models/shipments.py
@@ -20,7 +20,9 @@ class Shipment(models.Model):
RETURN_GPR = 2 # Good Part Return
RETURN_CTS = 3 # Convert to stock
- location = models.ForeignKey(Location, editable=False)
+ location = models.ForeignKey(Location,
+ editable=False,
+ on_delete=models.SET_NULL)
ship_to = models.CharField(
default='',
@@ -81,6 +83,7 @@ class Shipment(models.Model):
settings.AUTH_USER_MODEL,
null=True,
editable=False,
+ on_delete=models.SET_NULL,
related_name='dispatched_shipments'
)