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
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
def test_product_autocomplete(self, member1, client1, planninguser1): with tenant_context(member1.tenant): client1.force_login(planninguser1) factories.ProductFactory(name='test_product_autocomplete') factories.ProductFactory(name='bla') response = client1.get('%s?q=test_product_autocomplete' % reverse('purchase-product-autocomplete')) assert response.status_code == status.HTTP_200_OK assert len(response.data) == 1 assert response.data[0]['name'] == 'test_product_autocomplete'
def test_product_list_search(self, member1, client1, planninguser1): with tenant_context(member1.tenant): client1.force_login(planninguser1) factories.ProductFactory(name='test', ) factories.ProductFactory(name='nog een product', ) response = client1.get('%s?q=nog' % reverse('purchase-product-list')) assert response.status_code == status.HTTP_200_OK assert response.data['count'] == 1 assert response.data['results'][0]['name'] == 'nog een product'
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
def test_product_delete(self, member1, client1, planninguser1): with tenant_context(member1.tenant): client1.force_login(planninguser1) product = factories.ProductFactory(name='test') response = client1.delete(reverse('purchase-product-detail', kwargs={'pk': product.pk}), format='json') assert response.status_code == status.HTTP_204_NO_CONTENT
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
def test_product_retrieve(self, member1, client1, planninguser1): with tenant_context(member1.tenant): client1.force_login(planninguser1) product = factories.ProductFactory( name='test', identifier='1234', ) response = client1.get( reverse('purchase-product-detail', kwargs={'pk': product.id})) assert response.status_code == status.HTTP_200_OK assert response.data['identifier'] == '1234'
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
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
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
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
def test_product_update(self, member1, client1, planninguser1): with tenant_context(member1.tenant): client1.force_login(planninguser1) product = factories.ProductFactory( name='test', identifier='bla', ) response = client1.put( reverse('purchase-product-detail', kwargs={'pk': product.id}), { 'name': 'test name', 'identifier': 'bla', 'price_purchase': '0.00', 'price_selling': '0.00', 'price_selling_alt': '0.00', 'price_purchase_ex': '0.00', 'price_selling_ex': '0.00', 'price_selling_alt_ex': '0.00', }) assert response.status_code == status.HTTP_200_OK assert response.data['name'] == 'test name'