Esempio n. 1
0
def view_gsx_results(request, what="warranty"):
    """
    Searches for something from GSX. Defaults to warranty lookup.
    GSX search strings are always UPPERCASE.
    """
    results = list()
    data, query = prepare_result_view(request)
    query = query.upper()

    error_template = "search/results/gsx_error.html"

    if data['gsx_type'] == "dispatchId":
        what = "repairs"

    if data['gsx_type'] == "partNumber":
        what = "parts"

    data['what'] = what
    gsx_type = data['gsx_type']

    try:
        if request.session.get("current_queue"):
            queue = request.session['current_queue']
            GsxAccount.default(request.user, queue)
        else:
            GsxAccount.default(request.user)
    except gsxws.GsxError, e:
        error = {'message': e}
        return render(request, error_template, error)
Esempio n. 2
0
    def set_queue(self, queue_id, user):
        if self.is_closed:
            return

        if queue_id in (None, ''):
            queue_id = 0

        if isinstance(queue_id, Queue):
            queue = queue_id
        else:
            if int(queue_id) == 0:
                return self.unset_queue(user)

            queue = Queue.objects.get(pk=queue_id)

        self.queue = queue
        self.priority = queue.priority
        self.notify('set_queue', queue.title, user)

        if queue.gsx_soldto:
            gsx_account = GsxAccount.get_account(self.location, queue)
            for i in self.repair_set.filter(completed_at=None):
                i.gsx_account = gsx_account
                i.save()

        if queue.status_created:
            self.set_status(queue.status_created, user)
        else:
            self.save()
Esempio n. 3
0
    def create_from_gsx(cls, confirmation, order, device, user):
        """Creates a new Repair for order with confirmation number."""
        try:
            repair = cls.objects.get(confirmation=confirmation)
            msg = {'repair': repair.confirmation, 'order': repair.order}
            raise ValueError(
                _('Repair %(repair)s already exists for order %(order)s') %
                msg)
        except cls.DoesNotExist:
            pass

        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()

        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
Esempio n. 4
0
    def set_queue(self, queue_id, user):
        if self.is_closed:
            return

        if queue_id in (None, ''):
            queue_id = 0

        if isinstance(queue_id, Queue):
            queue = queue_id
        else:
            if int(queue_id) == 0:
                return self.unset_queue(user)

            queue = Queue.objects.get(pk=queue_id)

        self.queue = queue
        self.priority = queue.priority
        self.notify('set_queue', queue.title, user)

        if queue.gsx_soldto:
            gsx_account = GsxAccount.get_account(self.location, queue)
            for i in self.repair_set.filter(completed_at=None):
                i.gsx_account = gsx_account
                i.save()

        if queue.status_created:
            self.set_status(queue.status_created, user)
        else:
            self.save()
Esempio n. 5
0
File: repair.py Progetto: fpsw/Servo
    def create_from_gsx(cls, confirmation, order, device, user):
        """Creates a new Repair for order with confirmation number."""
        try:
            repair = cls.objects.get(confirmation=confirmation)
            msg = {"repair": repair.confirmation, "order": repair.order}
            raise ValueError(_("Repair %(repair)s already exists for order %(order)s") % msg)
        except cls.DoesNotExist:
            pass

        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()

        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
Esempio n. 6
0
def device_from_product(request, pk, item_id):
    """
    Turns a SOI into a device and attaches it to this order
    """
    order = get_object_or_404(Order, pk=pk)
    soi = ServiceOrderItem.objects.get(pk=item_id)

    try:
        GsxAccount.default(request.user, order.queue)
        device = Device.from_gsx(soi.sn, user=request.user)
        device.save()
        event = order.add_device(device, request.user)
        messages.success(request, event)
    except Exception as e:
        messages.error(request, e)

    return redirect(order)
Esempio n. 7
0
def device_from_product(request, pk, item_id):
    """
    Turns a SOI into a device and attaches it to this order
    """
    order = get_object_or_404(Order, pk=pk)
    soi = ServiceOrderItem.objects.get(pk=item_id)

    try:
        GsxAccount.default(request.user, order.queue)
        device = Device.from_gsx(soi.sn, user=request.user)
        device.save()
        event = order.add_device(device, request.user)
        messages.success(request, event)
    except Exception as e:
        messages.error(request, e)

    return redirect(order)
Esempio n. 8
0
def edit_product(request, pk, item_id):
    """
    Edits a product added to an order
    """
    order = Order.objects.get(pk=pk)
    item = get_object_or_404(ServiceOrderItem, pk=item_id)

    if not item.kbb_sn and item.product.part_type == "REPLACEMENT":
        try:
            device = order.devices.all()[0]
            item.kbb_sn = device.sn
        except IndexError:
            pass  # Probably no device in the order

    if item.product.component_code:
        try:
            GsxAccount.default(request.user, order.queue)
        except Exception as e:
            return render(request, "snippets/error_modal.html", {'error': e})

    form = OrderItemForm(instance=item)

    if request.method == "POST":
        form = OrderItemForm(request.POST, instance=item)
        if form.is_valid():
            try:
                item = form.save()
                # Set whoever set the KBB sn as the one who replaced the part
                if item.kbb_sn and not item.replaced_by:
                    item.replaced_by = request.user
                    item.save()

                messages.success(request, _(u"Product %s saved") % item.code)

                return redirect(order)
            except Exception as e:
                messages.error(request, e)

    product = item.product
    title = product.code
    prices = json.dumps(item.product.get_price())

    return render(request, "orders/edit_product.html", locals())
Esempio n. 9
0
def search_gsx(request, what, arg, value):
    if request.is_ajax():

        if what == "parts" and value != "None":
            results = []
            GsxAccount.default(user=request.user)

            try:
                product = gsxws.Product(productName=value)
                parts = product.parts()
                for p in parts:
                    results.append(Product.from_gsx(p))
            except gsxws.GsxError, e:
                data = {'message': e}
                return render(request, "search/results/gsx_error.html", data)

            data = {'results': results}

        return render(request, "search/results/gsx_%s.html" % what, data)
Esempio n. 10
0
def edit_product(request, pk, item_id):
    """
    Edits a product added to an order
    """
    order = Order.objects.get(pk=pk)
    item = get_object_or_404(ServiceOrderItem, pk=item_id)

    if not item.kbb_sn and item.product.part_type == "REPLACEMENT":
        try:
            device = order.devices.all()[0]
            item.kbb_sn = device.sn
        except IndexError:
            pass  # Probably no device in the order

    if item.product.component_code:
        try:
            GsxAccount.default(request.user, order.queue)
        except Exception as e:
            return render(request, "snippets/error_modal.html", {'error': e})

    form = OrderItemForm(instance=item)

    if request.method == "POST":
        form = OrderItemForm(request.POST, instance=item)
        if form.is_valid():
            try:
                item = form.save()
                # Set whoever set the KBB sn as the one who replaced the part
                if item.kbb_sn and not item.replaced_by:
                    item.replaced_by = request.user
                    item.save()

                messages.success(request, _(u"Product %s saved") % item.code)

                return redirect(order)
            except Exception as e:
                messages.error(request, e)

    product = item.product
    title = product.code
    prices = json.dumps(item.product.get_price())

    return render(request, "orders/edit_product.html", locals())