Ejemplo n.º 1
0
    def test_query_stock(self):

        in_transaction_1 = InTransaction.objects.create(
            in_product=self.phone_A,
            in_quantity=5,
            in_unit_price=10,
            in_purchase=self.purchase_1)

        ret = query.query_stock(product_id='PROD1')
        self.assertTrue(
            ret['stock_status'])
        self.assertEqual(
            ret['quantity'], 5)

        out_transaction_1 = OutTransaction.objects.create(
            out_product=self.phone_A,
            out_quantity=2,
            out_unit_price=15,
            out_serial='1111',
            out_sales=self.sales_1)

        ret = query.query_stock(product_id='PROD1')
        self.assertTrue(
            ret['stock_status'])
        self.assertEqual(
            ret['quantity'], 3)

        out_transaction_2 = OutTransaction.objects.create(
            out_product=self.phone_A,
            out_quantity=3,
            out_unit_price=15,
            out_serial='1111',
            out_sales=self.sales_1)

        ret = query.query_stock(product_id='PROD1')
        self.assertFalse(
            ret['stock_status'])
        self.assertEqual(
            ret['quantity'], 0)
Ejemplo n.º 2
0
def stock_list(request, store):
    """ handles stock list function
        support GET to query stock
    """
    if not request.user.is_authenticated():
        return HttpResponse("User is not authenticated.", status=403)
    
    logger.debug(request.path)
    logger.debug(request.method + " " + request.body)
    if request.method == 'GET':
        try:
            query.validate_query(request.GET)
            product_id = request.GET.get("product_id", None)
            product_name = request.GET.get("product_name", None)
            serial = request.GET.get("serial", None)
            data = query.query_stock(product_id=product_id,
                                           product_name=product_name,
                                           serial=serial)
            return HttpResponse(json.dumps(data))
        except ValidationError as ex:
            return HttpResponse(ex.value, status=403)
    else:
        return HttpResponse('Method ' +
                            request.method + " is not supported", status=403)