aboutsummaryrefslogtreecommitdiffstats
path: root/servo/models
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/models
parentec867584ef2078492d70b555ca419ea9e01dca8e (diff)
downloadServo-82e1fe63447f5c4d33d8a3ed7c365e7eab1006c0.tar.gz
Servo-82e1fe63447f5c4d33d8a3ed7c365e7eab1006c0.tar.bz2
Servo-82e1fe63447f5c4d33d8a3ed7c365e7eab1006c0.zip
May '16 GSX update changes
Diffstat (limited to 'servo/models')
-rw-r--r--servo/models/common.py4
-rw-r--r--servo/models/device.py15
-rw-r--r--servo/models/repair.py5
3 files changed, 19 insertions, 5 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):
"""