def test_should_search_item_by_description(self):
     consignee_item = ConsigneeItemFactory(consignee=self.consignee, item=ItemFactory(description='Plumpynut'))
     ConsigneeItemFactory(item=ItemFactory(description='AA'))
     response = self.client.get('%s?search=%s' % (ENDPOINT_URL, 'Plum'))
     results = response.data['results']
     self.assertEqual(len(results), 1)
     self.assertIn(consignee_item.id, [consignee_item['id'] for consignee_item in results])
    def test_should_filter_by_item_id(self):
        item = ItemFactory()
        consignee_item = ConsigneeItemFactory(item=item, consignee=self.consignee)
        ConsigneeItemFactory(consignee=self.consignee)

        response = self.client.get('%s?item=%d' % (ENDPOINT_URL, item.id))

        consignee_items = response.data['results']
        consignee_item_ids = [item['id'] for item in consignee_items]
        self.assertEqual(len(consignee_items), 1)
        self.assertIn(consignee_item.id, consignee_item_ids)
    def test_should_paginate_items_list(self):
        ConsigneeItemFactory(consignee=self.consignee)
        ConsigneeItemFactory(consignee=self.consignee)

        response = self.client.get(ENDPOINT_URL)

        self.assertIn('results', response.data)
        self.assertIn('count', response.data)
        self.assertIn('next', response.data)
        self.assertIn('previous', response.data)
        self.assertIn('pageSize', response.data)
        self.assertEqual(len(response.data['results']), 2)
Exemple #4
0
    def test_should_get_available_balance_of_item_distributed_by_consignee(self):
        consignee = ConsigneeFactory()
        po_item = PurchaseOrderItemFactory()
        node = DeliveryNodeFactory(consignee=consignee, item=po_item, quantity=150)

        consignee_item = ConsigneeItemFactory(consignee=consignee, item=po_item.item, amount_received=100,
                                              deliveries=[node.id])

        DeliveryNodeFactory(parents=[(node, 30)])
        DeliveryNodeFactory(parents=[(node, 25)])

        self.assertEqual(consignee_item.available_balance(), 45)
Exemple #5
0
    def test_should_get_available_balance_of_item_with_loss(self):
        consignee = ConsigneeFactory()
        po_item = PurchaseOrderItemFactory()
        node = DeliveryNodeFactory(consignee=consignee, item=po_item, quantity=50)

        consignee_item = ConsigneeItemFactory(consignee=consignee, item=po_item.item, amount_received=40,
                                              deliveries=[node.id])
        loss = DeliveryNodeLossFactory(quantity=10, delivery_node=node)

        DeliveryNodeFactory(parents=[(node, 15)])
        DeliveryNodeFactory(parents=[(node, 8)])

        self.assertEqual(consignee_item.available_balance(), 7)
Exemple #6
0
deliver_node_one = DeliveryNodeFactory(
    item=order_item,
    consignee=consignee_wakiso,
    distribution_plan=delivery_one,
    acknowledged=30,
    tree_position=DistributionPlanNode.IMPLEMENTING_PARTNER)
deliver_node_two = DeliveryNodeFactory(
    item=order_item,
    consignee=consignee_wakiso,
    distribution_plan=delivery_two,
    acknowledged=20,
    tree_position=DistributionPlanNode.IMPLEMENTING_PARTNER)
deliver_node_three = DeliveryNodeFactory(
    item=order_item_2,
    consignee=consignee_wakiso,
    distribution_plan=delivery_three,
    acknowledged=10,
    tree_position=DistributionPlanNode.IMPLEMENTING_PARTNER)

ArcFactory(quantity=30, source=None, target=deliver_node_one)
ArcFactory(quantity=20, source=None, target=deliver_node_two)
ArcFactory(quantity=10, source=None, target=deliver_node_three)

ConsigneeItemFactory(item=item,
                     amount_received=60,
                     consignee=consignee_wakiso,
                     deliveries=[
                         deliver_node_one.id, deliver_node_two.id,
                         deliver_node_three.id
                     ])