aboutsummaryrefslogtreecommitdiffstats
path: root/servo
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2016-05-01 19:03:53 +0300
committerFilipp Lepalaan <filipp@mac.com>2016-05-01 19:03:53 +0300
commit82e1fe63447f5c4d33d8a3ed7c365e7eab1006c0 (patch)
treecd96c0a704cb31837c6e0b2e9affe998d24acd7b /servo
parentec867584ef2078492d70b555ca419ea9e01dca8e (diff)
downloadServo-82e1fe63447f5c4d33d8a3ed7c365e7eab1006c0.tar.gz
Servo-82e1fe63447f5c4d33d8a3ed7c365e7eab1006c0.tar.bz2
Servo-82e1fe63447f5c4d33d8a3ed7c365e7eab1006c0.zip
May '16 GSX update changes
Diffstat (limited to 'servo')
-rw-r--r--servo/models/common.py4
-rw-r--r--servo/models/device.py15
-rw-r--r--servo/models/repair.py5
-rw-r--r--servo/urls/note.py2
-rw-r--r--servo/views/api.py2
-rw-r--r--servo/views/order.py2
-rw-r--r--servo/views/search.py7
7 files changed, 26 insertions, 11 deletions
diff --git a/servo/models/common.py b/servo/models/common.py
index 4d91296..7a1c79c 100644
--- a/servo/models/common.py
+++ b/servo/models/common.py
@@ -223,9 +223,11 @@ class GsxAccount(models.Model):
def get_shipto_choices(cls):
return cls.objects.values_list('ship_to', 'ship_to')
-
@classmethod
def get_default_account(cls):
+ """
+ Returns the default GSX account without connecting to it
+ """
from servo.lib.utils import empty
act_pk = Configuration.conf('gsx_account')
diff --git a/servo/models/device.py b/servo/models/device.py
index d422f92..0e244fc 100644
--- a/servo/models/device.py
+++ b/servo/models/device.py
@@ -289,7 +289,7 @@ class Device(models.Model):
return gsxws.Product(self.sn)
@classmethod
- def from_gsx(cls, sn, device=None, cached=True):
+ def from_gsx(cls, sn, device=None, cached=True, user=None):
"""
Initialize new Device with warranty info from GSX
Or update existing one
@@ -308,7 +308,14 @@ class Device(models.Model):
raise ValueError(_(u"Invalid input for warranty check: %s") % sn)
product = gsxws.Product(sn)
- wty = product.warranty()
+
+ if user and user.location:
+ ship_to = user.location.gsx_shipto
+ else:
+ gsx_act = GsxAccount.get_default_account()
+ ship_to = gsx_act.ship_to
+
+ wty = product.warranty(ship_to=gsx_act.ship_to)
model = product.model()
if device is None:
@@ -440,6 +447,10 @@ class Device(models.Model):
return diags.fetch()
def get_warranty(self):
+ """
+ Returns latest warranty info from GSX without
+ updating the Device record
+ """
return gsxws.Product(self.sn).warranty()
def get_repairs(self):
diff --git a/servo/models/repair.py b/servo/models/repair.py
index 2836759..93b348d 100644
--- a/servo/models/repair.py
+++ b/servo/models/repair.py
@@ -285,7 +285,8 @@ class Repair(models.Model):
self.connect_gsx(self.created_by)
product = gsxws.Product(self.device.sn)
parts = [(p.code, p.comptia_code,) for p in self.order.get_parts()]
- return product.warranty(parts, self.get_received_date())
+ return product.warranty(parts, self.get_received_date(),
+ ship_to=self.gsx_account.ship_to)
def is_open(self):
return self.completed_at is None
@@ -518,7 +519,7 @@ class Repair(models.Model):
User can also be different from the one who initially created the repair.
"""
account = user or self.created_by
- self.gsx_account.connect(account)
+ return self.gsx_account.connect(account)
def set_status(self, new_status, user):
"""
diff --git a/servo/urls/note.py b/servo/urls/note.py
index 5f74de3..e68bba3 100644
--- a/servo/urls/note.py
+++ b/servo/urls/note.py
@@ -19,7 +19,7 @@ urlpatterns = [
name="notes-create_to_customer"),
url(r'^(?P<pk>\d+)/toggle/tag/(?P<tag_id>\d+)/$', toggle_tag,
name="notes-toggle_tag"),
- url(r'^(?P<kind>\w+)/(?P<pk>\d+)/toggle_(?P<flag>[a-z]+)/$', toggle_flag,
+ url(r'^(?P<kind>\w+)?/(?P<pk>\d+)/toggle_(?P<flag>[a-z]+)/$', toggle_flag,
name="notes-toggle_flag"),
url(r'^(?P<parent>\d+)/reply/$', edit, name="notes-reply"),
url(r'^(?P<pk>\d+)/edit/$', edit, name="notes-edit"),
diff --git a/servo/views/api.py b/servo/views/api.py
index 9d2ba76..c8253bc 100644
--- a/servo/views/api.py
+++ b/servo/views/api.py
@@ -309,7 +309,7 @@ def warranty(request):
try:
GsxAccount.default(request.user)
except Exception as e:
- return error('Cannot connect to GSX (check user name and password)')
+ return error('Cannot connect to GSX (check username and password)')
try:
result = Device.from_gsx(sn, cached=False)
diff --git a/servo/views/order.py b/servo/views/order.py
index b4838f7..2ae34a1 100644
--- a/servo/views/order.py
+++ b/servo/views/order.py
@@ -631,7 +631,7 @@ def device_from_product(request, pk, item_id):
try:
GsxAccount.default(request.user, order.queue)
- device = Device.from_gsx(soi.sn)
+ device = Device.from_gsx(soi.sn, user=request.user)
device.save()
event = order.add_device(device, request.user)
messages.success(request, event)
diff --git a/servo/views/search.py b/servo/views/search.py
index 7640839..43f840f 100644
--- a/servo/views/search.py
+++ b/servo/views/search.py
@@ -21,6 +21,7 @@ from servo.models import (Note, Device, Product,
def search_gsx(request, what, param, query):
"""
The first phase of a GSX search. Sets up the GSX connection.
+ @TODO: Should this be in Device.from_gsx()?
"""
title = _(u'Search results for "%s"') % query
@@ -62,13 +63,13 @@ def get_gsx_search_results(request, what, param, query):
return render(request, "orders/list.html", locals())
if what == "warranty":
- # Update wty info if been here before
+ # Update wty info if device has been serviced before
try:
device = Device.objects.get(sn__exact=query)
device.update_gsx_details()
except Exception:
try:
- device = Device.from_gsx(query)
+ device = Device.from_gsx(query, user=request.user)
except Exception as e:
return render(request, error_template, {'message': e})
@@ -117,11 +118,11 @@ def get_gsx_search_results(request, what, param, query):
try:
device = gsxws.Product(query)
#results = device.repairs()
- # @TODO: move the encoding hack to py-gsxws
for i, p in enumerate(device.repairs()):
d = {'purchaseOrderNumber': p.purchaseOrderNumber}
d['repairConfirmationNumber'] = p.repairConfirmationNumber
d['createdOn'] = p.createdOn
+ # @TODO: move the encoding hack to py-gsxws
d['customerName'] = p.customerName.encode('utf-8')
d['repairStatus'] = p.repairStatus
results.append(d)