Пример #1
0
    def test_stockmutation_create_move(self, member1, client1, planninguser1):
        with tenant_context(member1.tenant):
            client1.force_login(planninguser1)
            product = factories.ProductFactory()
            fromLocation = factories.StockLocationFactory()
            toLocation = factories.StockLocationFactory()
            customer = CustomerFactory()

        response = client1.post(
            reverse('stockmutation-list'), {
                'product': product.id,
                'toLocation': toLocation.id,
                'fromLocation': fromLocation.id,
                'mutationType': 'move',
                'amount': 10,
                'customer': customer.id,
            })

        assert response.status_code == status.HTTP_201_CREATED

        # should result in one mutation row
        response = client1.get(reverse('stockmutation-list'))
        assert response.data['count'] == 1

        # check inventory
        from_inventory = purchase_models.StockLocationInventory.objects.get(
            product=product, location=fromLocation)

        assert from_inventory.amount == -10

        to_inventory = purchase_models.StockLocationInventory.objects.get(
            product=product, location=toLocation)

        assert to_inventory.amount == 10
Пример #2
0
    def test_stocklocationinventory_list_filter(self, member1, client1,
                                                planninguser1):
        with tenant_context(member1.tenant):
            client1.force_login(planninguser1)
            product1 = factories.ProductFactory(name='test product')

            location1 = factories.StockLocationFactory()

            factories.StockLocationInventoryFactory(
                product=product1,
                location=location1,
                amount=5,
            )

            product2 = factories.ProductFactory(name='nog een product')

            location2 = factories.StockLocationFactory()

            factories.StockLocationInventoryFactory(
                product=product2,
                location=location2,
                amount=5,
            )

        response = client1.get(
            '%s?location=%d' %
            (reverse('stocklocationinventory-list'), location1.id))

        assert response.status_code == status.HTTP_200_OK
        assert response.data['count'] == 1
        assert response.data['results'][0]['amount'] == 5
Пример #3
0
    def test_stocklocation_list_search(self, member1, client1, planninguser1):
        with tenant_context(member1.tenant):
            client1.force_login(planninguser1)
            factories.StockLocationFactory(name='test', )

            factories.StockLocationFactory(name='nog een location', )

        response = client1.get('%s?q=nog' % reverse('stocklocation-list'))

        assert response.status_code == status.HTTP_200_OK
        assert response.data['count'] == 1
        assert response.data['results'][0]['name'] == 'nog een location'
Пример #4
0
    def test_product_total_sales(self, member1, client1, planninguser1):
        with tenant_context(member1.tenant):
            client1.force_login(planninguser1)
            product1 = factories.ProductFactory(name='test product 1')

            product2 = factories.ProductFactory(name='test product 2')

            location = factories.StockLocationFactory()

        d = datetime.datetime.today().date()
        d += datetime.timedelta(days=1)

        if d.weekday() == 5:
            d += datetime.timedelta(days=2)

        if d.weekday() == 6:
            d += datetime.timedelta(days=1)

        response = client1.post(reverse('order-list'), {
            'customer_id':
            '1234',
            'start_date':
            d,
            'end_date':
            d,
            'order_type':
            'sales',
            'orderlines': [{
                'product_relation': product1.id,
                'location_relation': location.id,
                'amount': 10,
                'price_purchase': 1.00,
                'price_selling': 3.50
            }, {
                'product_relation': product1.id,
                'location_relation': location.id,
                'amount': 10,
                'price_purchase': 1.00,
                'price_selling': 3.50
            }, {
                'product_relation': product2.id,
                'location_relation': location.id,
                'amount': 5,
                'price_purchase': 0.50,
                'price_selling': 1.50
            }]
        },
                                format='json')

        assert response.status_code == status.HTTP_201_CREATED

        response = client1.get(reverse('purchase-product-total-sales'))

        assert response.status_code == status.HTTP_200_OK

        assert response.data['result'][0]['product_name'] == product1.name
        assert response.data['result'][0]['amount'] == 20

        assert response.data['result'][1]['product_name'] == product2.name
        assert response.data['result'][1]['amount'] == 5
Пример #5
0
    def test_stocklocation_delete(self, member1, client1, planninguser1):
        with tenant_context(member1.tenant):
            client1.force_login(planninguser1)
            stocklocation = factories.StockLocationFactory(name='test')

        response = client1.delete(reverse('stocklocation-detail',
                                          kwargs={'pk': stocklocation.id}),
                                  format='json')

        assert response.status_code == status.HTTP_204_NO_CONTENT
Пример #6
0
    def test_stocklocation_retrieve(self, member1, client1, planninguser1):
        with tenant_context(member1.tenant):
            client1.force_login(planninguser1)
            stocklocation = factories.StockLocationFactory(
                name='test',
                identifier='1234',
            )

        response = client1.get(
            reverse('stocklocation-detail', kwargs={'pk': stocklocation.id}))

        assert response.status_code == status.HTTP_200_OK
        assert response.data['identifier'] == '1234'
Пример #7
0
    def test_stocklocationinventory_delete(self, member1, client1,
                                           planninguser1):
        with tenant_context(member1.tenant):
            client1.force_login(planninguser1)
            prod1 = factories.ProductFactory()
            loc1 = factories.StockLocationFactory()

            inventory = factories.StockLocationInventoryFactory(
                product=prod1,
                location=loc1,
                amount=5,
            )

        url = reverse('stocklocationinventory-detail',
                      kwargs={'pk': inventory.id})
        response = client1.delete(url, format='json')

        assert response.status_code == status.HTTP_204_NO_CONTENT
Пример #8
0
    def test_stocklocationinventory_create(self, member1, client1,
                                           planninguser1):
        with tenant_context(member1.tenant):
            client1.force_login(planninguser1)
            prod1 = factories.ProductFactory()
            loc1 = factories.StockLocationFactory()

        response = client1.post(reverse('stocklocationinventory-list'), {
            'product': prod1.id,
            'location': loc1.id,
            'amount': 5,
        })

        assert response.status_code == status.HTTP_201_CREATED
        assert response.data['amount'] == 5

        response = client1.get(reverse('stocklocationinventory-list'))
        assert response.data['count'] == 1
Пример #9
0
    def test_stocklocationinventory_list(self, member1, client1,
                                         planninguser1):
        with tenant_context(member1.tenant):
            client1.force_login(planninguser1)
            product = factories.ProductFactory()
            location = factories.StockLocationFactory()

        factories.StockLocationInventoryFactory(
            product=product,
            location=location,
            amount=5,
        )

        response = client1.get(reverse('stocklocationinventory-list'))

        assert response.status_code == status.HTTP_200_OK
        assert response.data['count'] == 1
        assert response.data['results'][0]['amount'] == 5
Пример #10
0
    def test_stocklocationinventory_retrieve(self, member1, client1,
                                             planninguser1):
        with tenant_context(member1.tenant):
            client1.force_login(planninguser1)
            prod1 = factories.ProductFactory()
            loc1 = factories.StockLocationFactory()

        inventory = factories.StockLocationInventoryFactory(
            product=prod1,
            location=loc1,
            amount=5,
        )

        response = client1.get(
            reverse('stocklocationinventory-detail',
                    kwargs={'pk': inventory.id}))

        assert response.status_code == status.HTTP_200_OK
        assert response.data['amount'] == 5
Пример #11
0
    def test_stocklocationinventory_list_product_types(self, member1, client1,
                                                       planninguser1):
        with tenant_context(member1.tenant):
            client1.force_login(planninguser1)
            prod1 = factories.ProductFactory(product_type='type 1')

            prod2 = factories.ProductFactory(product_type='type 2')

            prod3 = factories.ProductFactory(product_type='type 3')

            loc1 = factories.StockLocationFactory()

            factories.StockLocationInventoryFactory(
                product=prod1,
                location=loc1,
                amount=5,
            )

            factories.StockLocationInventoryFactory(
                product=prod1,
                location=loc1,
                amount=15,
            )

            factories.StockLocationInventoryFactory(
                product=prod2,
                location=loc1,
                amount=5,
            )

            factories.StockLocationInventoryFactory(
                product=prod3,
                location=loc1,
                amount=5,
            )

        url = '%s?location_id=%s' % (
            reverse('stocklocationinventory-list-product-types'), loc1.id)
        response = client1.get(url)

        assert response.status_code == status.HTTP_200_OK
        assert len(response.data) == 3