From 82e1fe63447f5c4d33d8a3ed7c365e7eab1006c0 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Sun, 1 May 2016 19:03:53 +0300 Subject: May '16 GSX update changes --- servo/models/common.py | 4 +++- servo/models/device.py | 15 +++++++++++++-- servo/models/repair.py | 5 +++-- 3 files changed, 19 insertions(+), 5 deletions(-) (limited to 'servo/models') 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): """ -- cgit v1.2.3