def create_distribution_plan_parent_and_child_nodes(self, parent_details=None, child_details=None):
     created_parent_details = create_distribution_plan_node(self, parent_details)
     consignee_id = create_consignee(self)['id']
     if not child_details:
         child_details = {'distribution_plan': created_parent_details['distribution_plan'],
                          'parent': created_parent_details['id'], 'consignee': consignee_id}
     created_child_details = create_distribution_plan_node(self, child_details)
     return created_parent_details, created_child_details
    def test_should_create_distribution_plan_node_with_parent_node(self):
        parent_node = create_distribution_plan_node(self)
        consignee_id = create_consignee(self)['id']
        child_node_details = {'distribution_plan': parent_node['distribution_plan'],
                              'parent': parent_node['id'], 'consignee': consignee_id}

        created_child_node_details = create_distribution_plan_node(self, child_node_details)

        self.assertDictContainsSubset(child_node_details, created_child_node_details)
    def test_should_create_distribution_plan_node_with_parent_node(self):
        parent_node = create_distribution_plan_node(self)
        consignee_id = create_consignee(self)['id']
        child_node_details = {'distribution_plan': parent_node['distribution_plan'], 'consignee': consignee_id,
                              'tree_position': self.MIDDLEMAN_POSITION, 'parent': parent_node['id'],
                              'location': 'Kampala', 'mode_of_delivery': 'WAREHOUSE', 'contact_person_id': u'1234'}

        created_child_node_details = create_distribution_plan_node(self, child_node_details)

        self.assertDictContainsSubset(child_node_details, created_child_node_details)
 def create_distribution_plan_parent_and_child_nodes(self, parent_details=None, child_details=None):
     created_parent_details = create_distribution_plan_node(self, parent_details)
     consignee_id = create_consignee(self)['id']
     if not child_details:
         child_details = {'distribution_plan': created_parent_details['distribution_plan'],
                          'consignee': consignee_id, 'location': 'Kampala', 'mode_of_delivery': 'WAREHOUSE',
                          'contact_person_id': u'1234',
                          'tree_position': self.MIDDLEMAN_POSITION, 'parent': created_parent_details['id']}
     created_child_details = create_distribution_plan_node(self, child_details)
     return created_parent_details, created_child_details
Esempio n. 5
0
    def test_should_create_distribution_plan_node_with_parent_node(self):
        parent_node = create_distribution_plan_node(self)
        consignee_id = create_consignee(self)['id']
        child_node_details = {
            'distribution_plan': parent_node['distribution_plan'],
            'parent': parent_node['id'],
            'consignee': consignee_id
        }

        created_child_node_details = create_distribution_plan_node(
            self, child_node_details)

        self.assertDictContainsSubset(child_node_details,
                                      created_child_node_details)
    def test_should_filter_nodes_by_parent_null(self):
        parent_node = create_distribution_plan_node(self)
        consignee_id = create_consignee(self)['id']
        child_node_details = {'item': parent_node['item'], 'targeted_quantity': parent_node['targeted_quantity'],
                              'delivery_date': parent_node['delivery_date'],
                              'distribution_plan': parent_node['distribution_plan'], 'consignee': consignee_id,
                              'tree_position': self.MIDDLEMAN_POSITION, 'parent': parent_node['id'],
                              'location': 'Kampala', 'contact_person_id': u'1234'}
        create_distribution_plan_node(self, child_node_details)

        all_nodes = self.client.get(ENDPOINT_URL).data
        self.assertEqual(len(all_nodes), 2)

        parent_nodes = self.client.get(ENDPOINT_URL + "?parent__isnull=true").data
        self.assertEqual(len(parent_nodes), 1)
Esempio n. 7
0
 def create_distribution_plan_parent_and_child_nodes(
         self, parent_details=None, child_details=None):
     created_parent_details = create_distribution_plan_node(
         self, parent_details)
     consignee_id = create_consignee(self)['id']
     if not child_details:
         child_details = {
             'distribution_plan':
             created_parent_details['distribution_plan'],
             'parent': created_parent_details['id'],
             'consignee': consignee_id
         }
     created_child_details = create_distribution_plan_node(
         self, child_details)
     return created_parent_details, created_child_details
    def test_should_create_distribution_plan_node_without_parent_node(self):
        plan_id = create_distribution_plan(self)
        consignee_id = create_consignee(self)['id']
        node_details = {'distribution_plan': plan_id, 'consignee': consignee_id}

        created_node_data = create_distribution_plan_node(self, node_details)

        self.assertDictContainsSubset(node_details, created_node_data)
    def test_should_provide_distribution_plan_nodes_with_their_line_items(self):
        node_id = create_distribution_plan_node(self)['id']
        line_item_details = make_line_item_details(self, node_id)
        created_line_item = create_distribution_plan_line_item(self, line_item_details)
        expected_node_partial = {'distributionplanlineitem_set': [created_line_item['id']]}

        response = self.client.get("%s%d/" % (ENDPOINT_URL, node_id))

        self.assertEqual(response.status_code, 200)
        self.assertDictContainsSubset(expected_node_partial, response.data)
Esempio n. 10
0
    def test_should_create_distribution_plan_node_without_parent_node(self):
        plan_id = create_distribution_plan(self)
        consignee_id = create_consignee(self)['id']
        node_details = {
            'distribution_plan': plan_id,
            'consignee': consignee_id
        }

        created_node_data = create_distribution_plan_node(self, node_details)

        self.assertDictContainsSubset(node_details, created_node_data)
    def test_should_create_node_of_type_end_user(self):
        plan_id = create_distribution_plan(self)
        consignee = create_consignee(self)
        node_details = {'distribution_plan': plan_id, 'consignee': consignee['id'],
                        'tree_position': self.END_USER_POSITION, 'location': 'Kampala', 'mode_of_delivery': 'WAREHOUSE',
                        'contact_person_id': u'1234'}

        node = create_distribution_plan_node(self, node_details=node_details)

        response = self.client.get("%s%d/" % (ENDPOINT_URL, node['id']))
        self.assertDictContainsSubset({'tree_position': node['tree_position']}, response.data)
    def test_should_search_for_consignee_at_top_level(self):
        implementing_partner = {'name': "Save the Children", 'type': 'implementing_partner'}
        middle_man = {'name': "Kibuli DHO", 'type': 'middle_man'}

        implementing_partner_details = create_consignee(self, implementing_partner)
        create_consignee(self, middle_man)
        plan_id = create_distribution_plan(self)
        node_details = {'distribution_plan': plan_id, 'consignee': implementing_partner_details['id'], 'tree_position': 'END_USER',
                        'location': 'Kampala', 'mode_of_delivery': 'WAREHOUSE', 'contact_person_id': u'1234'}
        create_distribution_plan_node(self, node_details)

        get_response = self.client.get(ENDPOINT_URL + '?node=top')

        self.assertEqual(get_response.status_code, 200)
        self.assertDictContainsSubset(implementing_partner_details, get_response.data[0])
        self.assertEqual(1, len(get_response.data))

        get_response = self.client.get(ENDPOINT_URL + '?node=1')
        self.assertEqual(get_response.status_code, 200)
        self.assertEqual(2, len(get_response.data))
    def test_should_provide_distribution_plan_with_all_its_nodes(self):
        plan_id = create_distribution_plan(self)
        consignee = create_consignee(self)
        node_details = {'distribution_plan': plan_id, 'consignee': consignee['id']}
        node = create_distribution_plan_node(self, node_details)
        expected_plan_partial = {'distributionplannode_set': [node['id']]}

        response = self.client.get("%s%d/" % (ENDPOINT_URL, plan_id))

        self.assertEqual(response.status_code, 200)
        self.assertDictContainsSubset(expected_plan_partial, response.data)
Esempio n. 14
0
    def test_should_search_for_consignee_at_top_level(self):
        partner = ConsigneeFactory(name='Save the Children', type='implementing_partner')
        consignee = ConsigneeFactory(name='Kibuli DHO', type='middle_man')
        plan_id = DistributionPlanFactory(consignee=consignee).id
        item = create_sales_order_item(self)
        node_details = {'item': item['id'], 'targeted_quantity': 1, 'distribution_plan': plan_id,
                        'delivery_date': '2015-04-23', 'consignee': partner.id,
                        'tree_position': 'END_USER',
                        'location': 'Kampala', 'contact_person_id': u'1234', }

        create_distribution_plan_node(self, node_details)

        get_response = self.client.get(ENDPOINT_URL + '?node=top')

        self.assertEqual(get_response.status_code, 200)
        self.assertDictContainsSubset({'id': partner.id, 'name': partner.name}, get_response.data[0])
        self.assertEqual(1, len(get_response.data))

        get_response = self.client.get(ENDPOINT_URL + '?node=1')
        self.assertEqual(get_response.status_code, 200)
        self.assertEqual(2, len(get_response.data))
    def test_should_create_distribution_plan_line_item(self):
        item_unit = ItemUnit.objects.create(name='EA')
        item = Item.objects.create(description='Item 1', unit=item_unit)
        node = create_distribution_plan_node(self)
        item_details = {'item': item.id, 'quantity': 10,
                        'under_current_supply_plan': False, 'planned_distribution_date': '2014-01-21',
                        'destination_location': 'GULU',
                        'distribution_plan_node': node['id'], 'remark': "Dispatched"}

        returned_item = create_distribution_plan_line_item(self, item_details)

        self.assertDictContainsSubset(item_details, returned_item)
    def test_should_provide_distribution_plan_with_all_its_nodes(self):
        plan_id = create_distribution_plan(self)
        consignee = create_consignee(self)
        node_details = {'distribution_plan': plan_id, 'consignee': consignee['id'], 'tree_position': 'END_USER',
                        'location': 'Kampala', 'mode_of_delivery': 'WAREHOUSE', 'contact_person_id': u'1234'}
        node = create_distribution_plan_node(self, node_details)
        expected_plan_partial = {'distributionplannode_set': [node['id']]}

        response = self.client.get("%s%d/" % (ENDPOINT_URL, plan_id))

        self.assertEqual(response.status_code, 200)
        self.assertDictContainsSubset(expected_plan_partial, response.data)
    def test_should_create_distribution_plan_node_without_parent_node(self):
        plan_id = DistributionPlanFactory().id
        consignee_id = create_consignee(self)['id']
        sales_order_item = create_sales_order_item(self)
        node_details = {'item': sales_order_item['id'], 'targeted_quantity': 10,
                        'delivery_date': '2014-01-21', 'distribution_plan': plan_id,
                        'tree_position': self.MIDDLEMAN_POSITION,
                        'contact_person_id': u'1234',
                        'consignee': consignee_id, 'location': 'Kampala'}

        created_node_data = create_distribution_plan_node(self, node_details)

        self.assertDictContainsSubset(node_details, created_node_data)
    def test_should_provide_distribution_plan_with_all_its_nodes(self):
        plan_id = create_distribution_plan(self)
        consignee = create_consignee(self)
        node_details = {
            'distribution_plan': plan_id,
            'consignee': consignee['id']
        }
        node = create_distribution_plan_node(self, node_details)
        expected_plan_partial = {'distributionplannode_set': [node['id']]}

        response = self.client.get("%s%d/" % (ENDPOINT_URL, plan_id))

        self.assertEqual(response.status_code, 200)
        self.assertDictContainsSubset(expected_plan_partial, response.data)
Esempio n. 19
0
    def test_should_provide_distribution_plan_nodes_with_their_line_items(
            self):
        node_id = create_distribution_plan_node(self)['id']
        line_item_details = make_line_item_details(self, node_id)
        created_line_item = create_distribution_plan_line_item(
            self, line_item_details)
        expected_node_partial = {
            'distributionplanlineitem_set': [created_line_item['id']]
        }

        response = self.client.get("%s%d/" % (ENDPOINT_URL, node_id))

        self.assertEqual(response.status_code, 200)
        self.assertDictContainsSubset(expected_node_partial, response.data)
    def test_should_create_node_of_type_end_user(self):
        plan_id = DistributionPlanFactory().id
        consignee = create_consignee(self)
        sales_order_item = create_sales_order_item(self)
        node_details = {'item': sales_order_item['id'], 'targeted_quantity': 10,
                        'delivery_date': '2014-01-21',
                        'distribution_plan': plan_id, 'consignee': consignee['id'],
                        'tree_position': self.END_USER_POSITION, 'location': 'Kampala',
                        'contact_person_id': u'1234'}

        node = create_distribution_plan_node(self, node_details=node_details)

        response = self.client.get("%s%d/" % (ENDPOINT_URL, node['id']))
        self.assertDictContainsSubset({'tree_position': node['tree_position']}, response.data)
Esempio n. 21
0
    def test_should_create_distribution_plan_line_item(self):
        item_unit = ItemUnit.objects.create(name='EA')
        item = Item.objects.create(description='Item 1', unit=item_unit)
        node = create_distribution_plan_node(self)
        item_details = {
            'item': item.id,
            'quantity': 10,
            'under_current_supply_plan': False,
            'planned_distribution_date': '2014-01-21',
            'destination_location': 'GULU',
            'distribution_plan_node': node['id'],
            'remark': "Dispatched"
        }

        returned_item = create_distribution_plan_line_item(self, item_details)

        self.assertDictContainsSubset(item_details, returned_item)
    def test_should_create_distribution_plan_line_item(self):
        item_unit = ItemUnit.objects.create(name='EA')
        item = Item.objects.create(description='Item 1', unit=item_unit)
        sales_order = create_sales_order(self)

        sales_order_details = {'sales_order': sales_order['id'], 'item': item.id, 'quantity': 23,
                               'net_price': 12000.0, 'net_value': 100.0, 'issue_date': '2014-01-21',
                               'delivery_date': '2014-01-21'}

        sales_item_id = create_sales_order_item(self, sales_order_details)['id']

        node = create_distribution_plan_node(self)

        item_details = {'item': sales_item_id, 'targeted_quantity': 10, 'planned_distribution_date': '2014-01-21',
                        'remark': "Dispatched", 'distribution_plan_node': node['id']}

        returned_item = create_distribution_plan_line_item(self, item_details)

        self.assertDictContainsSubset(item_details, returned_item)