aboutsummaryrefslogtreecommitdiffstats
path: root/servo
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2015-09-10 14:19:40 +0300
committerFilipp Lepalaan <filipp@mac.com>2015-09-10 14:19:40 +0300
commit5db340c9b85887a03cf1010399776b840b8bda8e (patch)
tree6c77a2a2cba5d7b1fac512b507aa47e5956f5c72 /servo
parent2deb6a356aab1c18443748e7c6d693e60086ddcf (diff)
downloadServo-5db340c9b85887a03cf1010399776b840b8bda8e.tar.gz
Servo-5db340c9b85887a03cf1010399776b840b8bda8e.tar.bz2
Servo-5db340c9b85887a03cf1010399776b840b8bda8e.zip
Added GSX repair import
Diffstat (limited to 'servo')
-rw-r--r--servo/forms/repairs.py8
-rw-r--r--servo/models/repair.py29
-rwxr-xr-xservo/templates/orders/toolbar.html2
-rw-r--r--servo/templates/repairs/import_repair.html13
-rw-r--r--servo/urls/order.py30
-rw-r--r--servo/views/gsx.py32
6 files changed, 91 insertions, 23 deletions
diff --git a/servo/forms/repairs.py b/servo/forms/repairs.py
index b821ea9..d705152 100644
--- a/servo/forms/repairs.py
+++ b/servo/forms/repairs.py
@@ -35,6 +35,14 @@ from servo.models import User, Repair, Template
from servo.forms import BaseForm, AutocompleteTextarea, DateTimePickerInput, ChoiceField
+class ImportForm(BaseForm):
+ confirmation = forms.CharField(
+ min_length=8,
+ max_length=15,
+ label=_('Confirmation')
+ )
+
+
class GsxCustomerForm(BaseForm):
firstName = forms.CharField(max_length=100, label=_('First name'))
lastName = forms.CharField(max_length=100, label=_('Last name'))
diff --git a/servo/models/repair.py b/servo/models/repair.py
index 8d9ffab..24931b6 100644
--- a/servo/models/repair.py
+++ b/servo/models/repair.py
@@ -34,10 +34,8 @@ from django.db import models
from django.conf import settings
from django.utils import timezone
from django.core.urlresolvers import reverse
-from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _
from django.core.validators import MaxLengthValidator
-from django.contrib.sites.managers import CurrentSiteManager
from servo import defaults
from servo.lib.utils import cache_getset
@@ -49,12 +47,6 @@ from servo.models.purchases import PurchaseOrder, PurchaseOrderItem
class Checklist(models.Model):
- site = models.ForeignKey(
- Site,
- editable=False,
- default=defaults.site_id
- )
-
title = models.CharField(
max_length=255,
unique=True,
@@ -68,7 +60,6 @@ class Checklist(models.Model):
)
enabled = models.BooleanField(default=True, verbose_name=_("Enabled"))
- objects = CurrentSiteManager()
def get_admin_url(self):
return reverse('admin-edit_checklist', args=[self.pk])
@@ -249,7 +240,7 @@ class Repair(models.Model):
return len(replacements) == 1
@classmethod
- def create_from_gsx(cls, order, confirmation):
+ def create_from_gsx(cls, confirmation, order, device, user):
"""
Creates a new Repair for order with confirmation number
"""
@@ -260,11 +251,21 @@ class Repair(models.Model):
except cls.DoesNotExist:
pass
- repair = cls(order=order)
- repair.confirmation=confirmation
+ repair = cls(order=order, created_by=user)
+ repair.device = device
+ repair.confirmation = confirmation
+ repair.gsx_account = GsxAccount.default(user, order.queue)
+ repair.submitted_at = timezone.now() # RepairDetails doesn't have this!
repair.save()
- repair.update_details()
- repair.update_status()
+
+ try:
+ repair.get_details()
+ repair.update_status(user)
+ except gsxws.GsxError as e:
+ if e.code == 'RPR.LKP.01': # repair not found
+ repair.delete()
+ raise ValueError(_('Repair %s not found in GSX') % confirmation)
+
return repair
def create_purchase_order(self):
diff --git a/servo/templates/orders/toolbar.html b/servo/templates/orders/toolbar.html
index 4bd9fef..6588a52 100755
--- a/servo/templates/orders/toolbar.html
+++ b/servo/templates/orders/toolbar.html
@@ -105,8 +105,6 @@
<li class="disabled"><a href="#">{% trans "Order Products" %}</a></li>
{% endif %}
<li class="divider"></li>
- <li><a href="{% url 'repairs-import_repair' order.pk %}" data-modal="#modal">{% trans "Import GSX Repair" %}</a></li>
- <li class="divider"></li>
{% if perms.servo.delete_order and order.is_editable %}
<li><a href="{% url 'orders-delete_order' order.pk %}" data-modal="#modal"><i class="icon-trash"> </i> {% trans "Delete Order" %}</a></li>
{% else %}
diff --git a/servo/templates/repairs/import_repair.html b/servo/templates/repairs/import_repair.html
new file mode 100644
index 0000000..571b19e
--- /dev/null
+++ b/servo/templates/repairs/import_repair.html
@@ -0,0 +1,13 @@
+{% extends "modal.html" %}
+{% load i18n %}
+
+{% block header %}
+ {% trans "Import GSX Repair" %}
+{% endblock header %}
+
+{% block body %}
+ <form method="post" action="{{ action }}">
+ {% csrf_token %}
+ {% include "form_snippet.html" %}
+ </form>
+{% endblock body %}
diff --git a/servo/urls/order.py b/servo/urls/order.py
index da0b3e0..d57e5eb 100644
--- a/servo/urls/order.py
+++ b/servo/urls/order.py
@@ -1,3 +1,29 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2013, First Party Software
+# All rights reserved.
+
+# Redistribution and use in source and binary forms, with or without modification,
+# are permitted provided that the following conditions are met:
+
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
from servo.views import note
from django.conf.urls import patterns, url
from servo.views.order import update_order
@@ -98,8 +124,8 @@ urlpatterns = patterns(
name="orders-edit_note"),
url(r'^(\d+)/device/(\d+)/repairs/(\w+)/create/$', create_repair,
name="repairs-create_repair"),
+ url(r'^(\d+)/device/(\d+)/import_repair/$', import_repair,
+ name="repairs-import_repair"),
url(r'^(\d+)/repairs/(\d+)/edit/$', edit_repair, name="repairs-edit_repair"),
- url(r'^(\d+)/repairs/import/$', import_repair, name="repairs-import_repair"),
-
)
diff --git a/servo/views/gsx.py b/servo/views/gsx.py
index 1e20354..0269462 100644
--- a/servo/views/gsx.py
+++ b/servo/views/gsx.py
@@ -34,7 +34,7 @@ from django.shortcuts import render, redirect, get_object_or_404
from django.contrib.auth.decorators import permission_required
from servo.models import Order, GsxAccount, Repair, ServicePart
-from servo.forms import GsxCustomerForm, GsxRepairForm, GsxComponentForm
+from servo.forms import GsxCustomerForm, GsxRepairForm, GsxComponentForm, ImportForm
class RepairDetails(object):
@@ -56,15 +56,37 @@ def register_return(request, part_id):
try:
part.register_for_return(request.user)
messages.success(request, _(u"Part %s updated") % part.order_item.code)
- except Exception, e:
+ except Exception as e:
messages.error(request, e)
return redirect(part.repair.order)
@permission_required("servo.change_repair")
-def import_repair(request, pk):
- pass
+def import_repair(request, order_pk, device_pk):
+ from servo.models import Device
+ order = get_object_or_404(Order, pk=order_pk)
+ device = get_object_or_404(Device, pk=device_pk)
+
+ action = request.path
+ form = ImportForm()
+
+ if request.method == 'POST':
+ form = ImportForm(request.POST)
+ if form.is_valid():
+ confirmation = form.cleaned_data['confirmation']
+
+ try:
+ repair = Repair.create_from_gsx(confirmation,
+ order,
+ device,
+ request.user)
+ return redirect(repair)
+ except Exception as e:
+ messages.error(request, e)
+ return redirect(order)
+
+ return render(request, "repairs/import_repair.html", locals())
@permission_required("servo.change_order")
@@ -309,7 +331,7 @@ def create_repair(request, order_id, device_id, type):
try:
repair.gsx_account = GsxAccount.default(request.user, order.queue)
- except Exception, e:
+ except Exception as e:
messages.error(request, e)
return redirect(order)