Ejemplo n.º 1
0
 def to_gsx(self):
     """
     Returns the corresponding gsxws Product object
     """
     if len(self.imei):
         return gsxws.Product(self.imei)
     return gsxws.Product(self.sn)
Ejemplo n.º 2
0
    def __init__(self, *args, **kwargs):

        super(DeviceForm, self).__init__(*args, **kwargs)

        if Configuration.false('checkin_require_password'):
            self.fields['password'].required = False

        if Configuration.true('checkin_require_condition'):
            self.fields['condition'].required = True

        if kwargs.get('instance'):
            prod = gsxws.Product('')
            prod.description = self.instance.description

            if prod.is_ios:
                self.fields['password'].label = _('Passcode')

            if not prod.is_ios:
                del (self.fields['imei'])

            if not prod.is_mac:
                del (self.fields['username'])

        if Configuration.true('checkin_password'):
            self.fields['password'].widget = forms.TextInput(
                attrs={'class': 'span12'})
Ejemplo n.º 3
0
 def is_ios(self):
     """
     Returns True if this is an iOS device
     """
     p = gsxws.Product(self.sn)
     p.description = self.description
     return p.is_ios
Ejemplo n.º 4
0
 def warranty_status(self):
     """
     Gets warranty status for this device and these parts
     """
     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(),
                             ship_to=self.gsx_account.ship_to)
Ejemplo n.º 5
0
    def get_gsx_repairs(self):
        """Return this device's GSX repairs, if any."""
        device = gsxws.Product(self.get_sn())
        results = []

        for i, p in enumerate(device.repairs()):
            d = {'purchaseOrderNumber': p.purchaseOrderNumber}
            d['repairConfirmationNumber'] = p.repairConfirmationNumber
            d['createdOn'] = p.createdOn
            d['customerName'] = p.customerName.encode('utf-8')
            d['repairStatus'] = p.repairStatus
            results.append(d)

        return results
Ejemplo n.º 6
0
    def get_parts(self):
        """
        Returns GSX parts for a product with this device's serialNumber
        """
        results = {}
        cache_key = "%s_parts" % self.sn

        for p in gsxws.Product(self.sn).parts():
            product = Product.from_gsx(p)
            results[product.code] = product

        cache.set_many(results)
        cache.set(cache_key, results.values())

        return results.values()
Ejemplo n.º 7
0
def get_gsx_search_results(request, what, param, query):
    """
    The second phase of a GSX search.
    There should be an active GSX session open at this stage.
    """
    data = {}
    results = []
    query = query.upper()
    device = Device(sn=query)
    error_template = "search/results/gsx_error.html"

    # @TODO: this isn't a GSX search. Move it somewhere else.
    if what == "orders":
        try:
            if param == 'serialNumber':
                device = Device.objects.get(sn__exact=query)
            if param == 'alternateDeviceId':
                device = Device.objects.get(imei__exact=query)
        except (
                Device.DoesNotExist,
                ValueError,
        ):
            return render(request, "search/results/gsx_notfound.html")

        orders = device.order_set.all()
        return render(request, "orders/list.html", locals())

    if what == "warranty":
        # 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, user=request.user)
            except Exception as e:
                return render(request, error_template, {'message': e})

        results.append(device)

        # maybe it's a device we've already replaced...
        try:
            soi = ServiceOrderItem.objects.get(sn__iexact=query)
            results[0].repeat_service = soi.order
        except ServiceOrderItem.DoesNotExist:
            pass

    if what == "parts":
        # looking for parts
        if param == "partNumber":
            # ... with a part number
            part = gsxws.Part(partNumber=query)

            try:
                partinfo = part.lookup()
            except gsxws.GsxError as e:
                return render(request, error_template, {'message': e})

            product = Product.from_gsx(partinfo)
            cache.set(query, product)
            results.append(product)

        if param == "serialNumber":
            try:
                dev = Device.from_gsx(query)
                products = dev.get_parts()
                return render(request, "devices/parts.html", locals())
            except gsxws.GsxError as message:
                return render(request, "search/results/gsx_error.html",
                              locals())

        if param == "productName":
            product = gsxws.Product(productName=query)
            parts = product.parts()
            for p in parts:
                results.append(Product.from_gsx(p))

    if what == "repairs":
        # Looking for GSX repairs
        if param == "serialNumber":
            # ... with a serial number
            try:
                device = gsxws.Product(query)
                #results = device.repairs()
                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)
            except gsxws.GsxError as e:
                return render(request, "search/results/gsx_notfound.html")

        elif param == "dispatchId":
            # ... with a repair confirmation number
            repair = gsxws.Repair(number=query)
            try:
                results = repair.lookup()
            except gsxws.GsxError as message:
                return render(request, error_template, locals())

    return render(request, "devices/search_gsx_%s.html" % what, locals())
Ejemplo n.º 8
0
 def get_repairs(self):
     return gsxws.Product(self.sn).repairs()
Ejemplo n.º 9
0
 def get_warranty(self):
     """
     Returns latest warranty info from GSX without
     updating the Device record
     """
     return gsxws.Product(self.sn).warranty()
Ejemplo n.º 10
0
 def get_activation(self):
     return gsxws.Product(self.sn).activation()
Ejemplo n.º 11
0
 def is_mac(self):
     """Return True if this is a Mac."""
     p = gsxws.Product(self.sn)
     p.description = self.description
     return p.is_mac
Ejemplo n.º 12
0
    def from_gsx(cls, sn, device=None, cached=True, user=None):
        """
        Initialize new Device with warranty info from GSX
        Or update existing one
        """
        sn = sn.upper()
        cache_key = 'device-%s' % sn

        # Only cache unsaved devices
        if cached and device is None:
            if cache.get(cache_key):
                return cache.get(cache_key)

        arg = gsxws.validate(sn)

        if arg not in ("serialNumber", "alternateDeviceId",):
            raise ValueError(_(u"Invalid input for warranty check: %s") % sn)

        product = gsxws.Product(sn)

        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=ship_to)
        model = product.model()

        if device is None:
            # serialNumber may sometimes come back empty
            serial_number = wty.serialNumber or sn
            device = Device(sn=serial_number)

        from servo.lib.utils import empty

        if empty(device.notes):
            device.notes = wty.notes or ''
            device.notes += wty.csNotes or ''

        device.has_onsite = product.has_onsite
        device.is_vintage = product.is_vintage
        device.description = product.description
        device.fmip_active = product.fmip_is_active

        device.slug = slugify(device.description)
        device.configuration = wty.configDescription or ''
        device.purchase_country = countries.by_name(wty.purchaseCountry)

        device.config_code = model.configCode
        device.product_line = model.productLine.replace(" ", "")
        device.parts_and_labor_covered = product.parts_and_labor_covered

        device.sla_description = wty.slaGroupDescription or ''
        device.contract_start_date = wty.contractCoverageStartDate
        device.contract_end_date = wty.contractCoverageEndDate
        device.onsite_start_date = wty.onsiteStartDate
        device.onsite_end_date = wty.onsiteEndDate

        if wty.estimatedPurchaseDate:
            device.purchased_on = wty.estimatedPurchaseDate

        device.image_url = wty.imageURL or ''
        device.manual_url = wty.manualURL or ''
        device.exploded_view_url = wty.explodedViewURL or ''

        if wty.warrantyStatus:
            device.set_wty_status(wty.warrantyStatus)

        if product.is_ios:
            ad = device.get_activation()
            device.imei = ad.imeiNumber or ''
            device.unlocked = product.is_unlocked(ad)
            device.applied_activation_policy = ad.appliedActivationDetails or ''
            device.initial_activation_policy = ad.initialActivationPolicyDetails or ''
            device.next_tether_policy = ad.nextTetherPolicyDetails or ''

        cache.set(cache_key, device)

        return device