def product(request, sku): if not request.user.is_superuser: return HttpResponse(status=403) snapshots = ProductInventorySnapshot.objects.filter(sku=sku).order_by("-date_added") bc_snapshot = None vhq_snapshot = None if snapshots.filter(store="O").count() > 0: bc_snapshot = snapshots.filter(store="O")[0] if snapshots.filter(store="R").count() > 0: vhq_snapshot = snapshots.filter(store="R")[0] bc = standard_bc_connector() vhq = standard_vhq_connector() if not snapshots.count(): return HttpResponseRedirect("/inventory/update?next=/inventory/products/%s/" % sku) if request.method == 'POST': inventory = int(request.POST['inventory']) global_snapshot = ProductInventorySnapshot(sku=sku, inventory_count=inventory, store="G") global_snapshot.save() if bc_snapshot: bc.update_product_inventory(inventory, product_id=bc_snapshot.product_id, sku_id=bc_snapshot.sku_id) if vhq_snapshot: vhq.update_product_inventory(inventory, product_id=vhq_snapshot.vhq_product_id) snapshots = ProductInventorySnapshot.objects.filter(sku=sku).order_by("-date_added") if vhq_snapshot: product_name = vhq_snapshot.name else: product_name = bc_snapshot.name current_bc_product = None current_vhq_product = None if bc_snapshot: current_bc_product = bc.get_current_product(product_id=bc_snapshot.product_id, sku_id=bc_snapshot.sku_id) if vhq_snapshot: current_vhq_product = vhq.get_current_product(product_id=vhq_snapshot.vhq_product_id) global_snapshot = None if snapshots.filter(store='G').count() > 0: global_snapshot = snapshots.filter(store='G')[0] actual_inventory = None if global_snapshot: actual_inventory = global_snapshot.inventory_count if current_bc_product: actual_inventory -= global_snapshot.inventory_count - current_bc_product.inventory_count if current_vhq_product: actual_inventory -= global_snapshot.inventory_count - current_vhq_product.inventory_count return render_to_response("product.html", {"snapshots":snapshots, "product_name":product_name, "sku":sku, "current_bc_product":current_bc_product, "current_vhq_product":current_vhq_product, "global_snapshot":global_snapshot, "actual_inventory":actual_inventory}, context_instance=RequestContext(request))
def setUp(self): self.vhq = standard_vhq_connector() self.products = self.vhq.products()