Exemplo n.º 1
0
 def test_product_filter(self):
     ItemFactory(creating_task=self.task, amount=3)
     included_other_product_type = ProductTypeFactory()
     included_other_task = TaskFactory(
         process_type=self.process_type,
         product_type=included_other_product_type)
     included_other_item = ItemFactory(creating_task=included_other_task,
                                       amount=7)
     excluded_other_product_type = ProductTypeFactory()
     excluded_other_task = TaskFactory(
         process_type=self.process_type,
         product_type=excluded_other_product_type)
     excluded_other_item = ItemFactory(creating_task=excluded_other_task,
                                       amount=7)
     product_ids = [
         str(i)
         for i in [self.product_type.id, included_other_product_type.id]
     ]
     product_id_string = ','.join(product_ids)
     query_params = {
         'team': self.product_type.team_created_by.id,
         'product_types': product_id_string
     }
     response = self.client.get(self.url, query_params, format='json')
     self.assertEqual(len(response.data['results']), 2)
     response_product_ids = [
         response.data['results'][0]['product_id'],
         response.data['results'][1]['product_id']
     ]
     self.assertEqual(sorted(product_ids), sorted(response_product_ids))
Exemplo n.º 2
0
    def test_create_movement(self):
        task1 = TaskFactory(process_type=self.process_type,
                            product_type=self.product_type)
        task2 = TaskFactory(process_type=self.process_type,
                            product_type=self.product_type)
        task3 = TaskFactory(process_type=self.process_type,
                            product_type=self.product_type)
        old_item1 = ItemFactory(creating_task=task1)
        old_item2 = ItemFactory(creating_task=task2)
        old_item3 = ItemFactory(creating_task=task3)
        self.assertEqual(old_item1.team_inventory, self.sending_team)
        self.assertEqual(old_item2.team_inventory, self.sending_team)
        self.assertEqual(old_item3.team_inventory, self.sending_team)
        url = reverse('create_movement')
        data = {
            'origin': self.process_type.created_by.id,
            'team_origin': self.sending_team.id,
            'team_destination': self.receiving_team.id,
            'items': [{
                'item': old_item1.id
            }, {
                'item': old_item2.id
            }]
        }
        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, 201)

        new_item1 = Item.objects.get(id=old_item1.id)
        new_item2 = Item.objects.get(id=old_item2.id)
        new_item3 = Item.objects.get(id=old_item3.id)
        self.assertEqual(new_item1.team_inventory, self.receiving_team)
        self.assertEqual(new_item2.team_inventory, self.receiving_team)
        self.assertEqual(new_item3.team_inventory, self.sending_team)
Exemplo n.º 3
0
 def test_aggregate_products(self):
     process_type = ProcessTypeFactory()
     product_type1 = ProductTypeFactory()
     product_type2 = ProductTypeFactory()
     task1 = TaskFactory(process_type=process_type,
                         product_type=product_type1)
     ItemFactory(creating_task=task1, amount=2.3)
     task2 = TaskFactory(process_type=process_type,
                         product_type=product_type2)
     ItemFactory(creating_task=task2, amount=4.1)
     query_params = {'team': self.team.id, 'aggregate_products': 'true'}
     response = self.client.get(self.url, query_params)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data), 1)
     row = response.data[0]
     self.assertEqual(row['process_type']['id'], task1.process_type.id)
     self.assertEqual(row['process_type']['name'], process_type.name)
     self.assertEqual(row['process_type']['code'], process_type.code)
     self.assertEqual(row['process_type']['unit'], process_type.unit)
     self.assertEqual(row['process_type']['icon'], process_type.icon)
     self.assertEqual(len(row['product_types']), 2)
     result_products = [
         row['product_types'][0]['id'], row['product_types'][1]['id']
     ]
     self.assertEqual(sorted(result_products),
                      sorted([product_type1.id, product_type2.id]))
     self.assertEqual(row['amount'], Decimal('6.4'))
Exemplo n.º 4
0
 def test_adjustments_and_items(self):
     ItemFactory(creating_task=self.task, amount=11.1)
     AdjustmentFactory(
         process_type=self.process_type,
         product_type=self.product_type,
         amount=22.4,
     )
     ItemFactory(creating_task=self.task, amount=33.9)
     AdjustmentFactory(
         process_type=self.process_type,
         product_type=self.product_type,
         amount=44.6,
     )
     ItemFactory(creating_task=self.task, amount=55.5)
     response = self.client.get(self.url, self.query_params, format='json')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data), 5)
     self.assertEqual(response.data[0]['data']['created_amount'],
                      Decimal('55.500'))
     self.assertEqual(response.data[1]['data']['amount'], Decimal('44.600'))
     self.assertEqual(response.data[2]['data']['created_amount'],
                      Decimal('33.900'))
     self.assertEqual(response.data[3]['data']['amount'], Decimal('22.400'))
     self.assertEqual(response.data[4]['data']['created_amount'],
                      Decimal('11.100'))
Exemplo n.º 5
0
 def test_items(self):
     ItemFactory(creating_task=self.task, amount=18.2)
     ItemFactory(creating_task=self.task, amount=9.4)
     response = self.client.get(self.url, self.query_params, format='json')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data), 1)
     item_summary = response.data[0]
     self.assertEqual(item_summary['type'], 'item_summary')
     self.assertEqual(item_summary['data']['created_amount'],
                      Decimal('27.600'))
     self.assertEqual(item_summary['data']['used_amount'], 0)
Exemplo n.º 6
0
 def test_flag_filter(self):
     unflagged_task = TaskFactory()
     flagged_task = TaskFactory(is_flagged=True,
                                process_type=unflagged_task.process_type,
                                product_type=unflagged_task.product_type)
     ItemFactory(creating_task=unflagged_task, amount=2.3)
     ItemFactory(creating_task=flagged_task, amount=5.9)
     query_params = {'team': self.team.id, 'flagged': 'true'}
     response = self.client.get(self.url, query_params)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data), 1)
     row = response.data[0]
     self.assertEqual(row['runs'], 1)
     self.assertEqual(row['amount'], Decimal('5.9'))
Exemplo n.º 7
0
    def test_team_filter(self):
        item = ItemFactory(creating_task=self.task, amount=3)

        other_team = TeamFactory(name='other-team')
        other_team_process_type = ProcessTypeFactory(
            team_created_by=other_team)
        other_team_product_type = ProductTypeFactory(
            team_created_by=other_team)
        other_team_task = TaskFactory(process_type=other_team_process_type,
                                      product_type=other_team_product_type)
        other_team_item = ItemFactory(creating_task=other_team_task, amount=34)

        response = self.client.get(self.url, self.query_params, format='json')
        self.assertEqual(len(response.data['results']), 1)
Exemplo n.º 8
0
 def test_items_after_adjustment(self):
     with mock.patch('django.utils.timezone.now') as mock_now:
         mock_now.return_value = self.past_time
         adjustment = AdjustmentFactory(
             process_type=self.process_type,
             product_type=self.product_type,
             amount=45.6,
         )
     ItemFactory(creating_task=self.task, amount=3.1)
     ItemFactory(creating_task=self.task, amount=19.2)
     response = self.client.get(self.url, self.query_params, format='json')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data['results']), 1)
     self.assertEqual(response.data['results'][0]['adjusted_amount'],
                      Decimal('67.900'))
Exemplo n.º 9
0
 def test_items_only(self):
     ItemFactory(creating_task=self.task, amount=18.1)
     ItemFactory(creating_task=self.task, amount=3.2)
     response = self.client.get(self.url, self.query_params, format='json')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data['results']), 1)
     item = response.data['results'][0]
     self.assertEqual(item['process_id'], str(self.process_type.id))
     self.assertEqual(item['process_name'], 'process-name')
     self.assertEqual(item['process_unit'], 'process-unit')
     self.assertEqual(item['process_code'], 'process-code')
     self.assertEqual(item['product_id'], str(self.product_type.id))
     self.assertEqual(item['product_name'], 'product-name')
     self.assertEqual(item['product_code'], 'product-code')
     self.assertEqual(item['adjusted_amount'], Decimal('21.300'))
Exemplo n.º 10
0
 def test_exlude_items_with_deleted_tasks(self):
     deleted_task = TaskFactory(process_type=self.process_type,
                                product_type=self.product_type,
                                is_trashed=True)
     item = ItemFactory(creating_task=deleted_task, amount=3)
     response = self.client.get(self.url, self.query_params, format='json')
     self.assertEqual(len(response.data['results']), 0)
Exemplo n.º 11
0
 def setUp(self):
     self.product_type = ProductTypeFactory(name='product-name',
                                            code='product-code')
     self.process_type = ProcessTypeFactory(name='process-name',
                                            code='pc',
                                            unit='process-unit')
     self.task = TaskFactory.create(process_type=self.process_type,
                                    product_type=self.product_type)
     self.item = ItemFactory()
Exemplo n.º 12
0
 def test_input_with_amount(self):
     item = ItemFactory(creating_task=self.task, amount=32.4)
     ingredient = IngredientFactory(process_type=self.process_type,
                                    product_type=self.product_type)
     task_ingredient = TaskIngredientFactory(actual_amount=8.1,
                                             ingredient=ingredient)
     response = self.client.get(self.url, self.query_params, format='json')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data['results']), 1)
     self.assertEqual(response.data['results'][0]['adjusted_amount'],
                      Decimal('24.300'))
Exemplo n.º 13
0
 def test_partial_inputs(self):
     partially_used_item = ItemFactory(creating_task=self.task, amount=39.3)
     ingredient = IngredientFactory(process_type=self.process_type,
                                    product_type=self.product_type)
     task_ingredient = TaskIngredientFactory(actual_amount=7.8,
                                             ingredient=ingredient)
     response = self.client.get(self.url, self.query_params, format='json')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data), 1)
     item_summary = response.data[0]
     self.assertEqual(item_summary['type'], 'item_summary')
     self.assertEqual(item_summary['data']['created_amount'],
                      Decimal('39.300'))
     self.assertEqual(item_summary['data']['used_amount'], Decimal('7.800'))
Exemplo n.º 14
0
 def test_other_items(self):
     wrong_process_task = TaskFactory(process_type=ProcessTypeFactory(),
                                      product_type=self.product_type)
     wrong_product_task = TaskFactory(process_type=self.process_type,
                                      product_type=ProductTypeFactory())
     deleted_task = TaskFactory(process_type=self.process_type,
                                product_type=self.product_type,
                                is_trashed=True)
     other_team = TeamFactory(name='other-team')
     ItemFactory(creating_task=wrong_process_task)
     ItemFactory(creating_task=wrong_product_task)
     ItemFactory(creating_task=deleted_task)
     other_team_item = ItemFactory(creating_task=self.task)
     other_team_item.team_inventory = other_team
     other_team_item.save()
     response = self.client.get(self.url, self.query_params, format='json')
     self.assertEqual(len(response.data), 1)
Exemplo n.º 15
0
 def test_activity_list(self):
     process_type = ProcessTypeFactory(icon='someicon.png',
                                       name='process-type-name',
                                       code='ptc',
                                       unit='kg')
     task1 = TaskFactory(process_type=process_type)
     task2 = TaskFactory(process_type=process_type)
     ItemFactory(creating_task=task1, amount=29.7)
     response = self.client.get(self.url, self.query_params)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data), 2)
     row = response.data[0]
     self.assertEqual(row['runs'], 1)
     self.assertEqual(row['process_type']['id'], process_type.id)
     self.assertEqual(row['process_type']['name'], process_type.name)
     self.assertEqual(row['process_type']['code'], process_type.code)
     self.assertEqual(row['process_type']['unit'], process_type.unit)
     self.assertEqual(row['process_type']['icon'], process_type.icon)
     self.assertEqual(len(row['product_types']), 1)
     self.assertEqual(row['product_types'][0]['id'], task1.product_type.id)
     self.assertEqual(row['amount'], Decimal('29.700'))
Exemplo n.º 16
0
 def setUp(self):
     self.process_type = ProcessTypeFactory()
     self.url = reverse('production_actuals')
     with mock.patch('django.utils.timezone.now') as mock_now:
         mock_now.return_value = timezone.make_aware(
             datetime.datetime(2018, 1, 10), timezone.utc)
         task1 = TaskFactory(label='Jan-Task',
                             process_type=self.process_type)
         ItemFactory.create(creating_task=task1, amount=576)
     with mock.patch('django.utils.timezone.now') as mock_now:
         mock_now.return_value = timezone.make_aware(
             datetime.datetime(2018, 1, 11), timezone.utc)
         task2 = TaskFactory(label='Jan-Task',
                             process_type=self.process_type)
         ItemFactory.create(creating_task=task2, amount=14)
     with mock.patch('django.utils.timezone.now') as mock_now:
         mock_now.return_value = timezone.make_aware(
             datetime.datetime(2018, 2, 10), timezone.utc)
         task3 = TaskFactory(label='Feb-Task',
                             process_type=self.process_type)
         ItemFactory.create(creating_task=task3, amount=819)