Exemplo n.º 1
0
    def test_should_get_track_status_if_delivery_is_just_saved(self):
        order = PurchaseOrderFactory()
        order_item = PurchaseOrderItemFactory(purchase_order=order, quantity=100)
        delivery_one = DeliveryFactory(track=False)
        NodeFactory(item=order_item, distribution_plan=delivery_one, quantity=100, track=False)

        self.assertEqual(order.track(), PurchaseOrder.NOT_TRACKED)
Exemplo n.º 2
0
    def test_should_get_track_status_if_delivery_is_sent_partially(self):
        order = PurchaseOrderFactory()
        order_item = PurchaseOrderItemFactory(purchase_order=order, quantity=100)
        delivery_one = DeliveryFactory(track=True)
        NodeFactory(item=order_item, distribution_plan=delivery_one, quantity=50, track=True)

        self.assertEqual(order.track(), PurchaseOrder.PARTIALLY_TRACKED)
Exemplo n.º 3
0
    def test_should_know_if_it_is_fully_delivered_or_not(self):
        consignee = ConsigneeFactory()
        purchase_order_one = PurchaseOrderFactory()
        purchase_order_two = PurchaseOrderFactory()
        purchase_order_three = PurchaseOrderFactory()

        purchase_order_item_one = PurchaseOrderItemFactory(purchase_order=purchase_order_one, quantity=100)
        self.assertFalse(purchase_order_one.is_fully_delivered())

        NodeFactory(item=purchase_order_item_one, consignee=consignee, targeted_quantity=50,
                    tree_position=DistributionPlanNode.END_USER)
        self.assertFalse(purchase_order_one.is_fully_delivered())

        purchase_order_item_two = PurchaseOrderItemFactory(purchase_order=purchase_order_two, quantity=100)
        node_one = NodeFactory(item=purchase_order_item_two, consignee=consignee, targeted_quantity=100,
                    tree_position=DistributionPlanNode.IMPLEMENTING_PARTNER)
        node_two = NodeFactory(item=purchase_order_item_two, consignee=consignee, targeted_quantity=100,
                    tree_position=DistributionPlanNode.MIDDLE_MAN, parent=node_one)
        NodeFactory(item=purchase_order_item_two, consignee=consignee, targeted_quantity=100,
                               tree_position=DistributionPlanNode.MIDDLE_MAN, parent=node_two)
        self.assertTrue(purchase_order_two.is_fully_delivered())

        purchase_order_item_three = PurchaseOrderItemFactory(purchase_order=purchase_order_three, quantity=100)
        purchase_order_item_four = PurchaseOrderItemFactory(purchase_order=purchase_order_three, quantity=50)
        NodeFactory(item=purchase_order_item_three, consignee=consignee, targeted_quantity=100, tree_position=DistributionPlanNode.IMPLEMENTING_PARTNER)
        NodeFactory(item=purchase_order_item_four, consignee=consignee, targeted_quantity=50, tree_position=DistributionPlanNode.IMPLEMENTING_PARTNER)
        self.assertTrue(purchase_order_three.is_fully_delivered())
Exemplo n.º 4
0
    def test_should_return_multiple_deliveries_along_with_their_corresponding_nodes(self):
        order = PurchaseOrderFactory()
        order_item_one = PurchaseOrderItemFactory(purchase_order=order)
        order_item_two = PurchaseOrderItemFactory(purchase_order=order)
        delivery_one = DistributionPlanFactory()
        delivery_two = DistributionPlanFactory()
        node_one = NodeFactory(item=order_item_one, distribution_plan=delivery_one)
        node_two = NodeFactory(item=order_item_two, distribution_plan=delivery_one)
        node_three = NodeFactory(item=order_item_one, distribution_plan=delivery_two)
        node_four = NodeFactory(item=order_item_two, distribution_plan=delivery_two)

        deliveries = order.deliveries()

        self.assertEqual(len(deliveries), 2)
        self.assertListEqual(deliveries, [delivery_one, delivery_two])

        first_delivery_nodes = delivery_one.distributionplannode_set.all()
        second_delivery_nodes = delivery_two.distributionplannode_set.all()
        self.assertIn(node_one, first_delivery_nodes)
        self.assertIn(node_two, first_delivery_nodes)
        self.assertIn(node_three, second_delivery_nodes)
        self.assertIn(node_four, second_delivery_nodes)
Exemplo n.º 5
0
    def test_should_know_if_it_is_fully_delivered_or_not_using_only_tracked_nodes(self):
        purchase_order = PurchaseOrderFactory()

        item_one = PurchaseOrderItemFactory(purchase_order=purchase_order, quantity=100)
        item_two = PurchaseOrderItemFactory(purchase_order=purchase_order, quantity=100)
        self.assertFalse(purchase_order.is_fully_delivered())

        delivery = DeliveryFactory()
        node_one = NodeFactory(item=item_one, quantity=100, distribution_plan=delivery)
        self.assertFalse(purchase_order.is_fully_delivered())

        node_two = NodeFactory(item=item_two, quantity=100, distribution_plan=delivery)
        self.assertFalse(purchase_order.is_fully_delivered())

        delivery.track = True
        delivery.save()
        node_two.quantity = 50
        node_two.save()
        self.assertFalse(purchase_order.is_fully_delivered())

        node_two.quantity = 100
        node_two.save()
        self.assertTrue(purchase_order.is_fully_delivered())
Exemplo n.º 6
0
    def test_gets_correct_last_shipment_date_value_for_stock_report(self):
        programme = ProgrammeFactory(name='special_program')
        delivery = DeliveryFactory(track=True, programme=programme)
        sales_order = SalesOrderFactory(programme=programme)
        purchase_order = PurchaseOrderFactory(order_number=4748278,
                                              sales_order=sales_order)
        po_item = PurchaseOrderItemFactory(purchase_order=purchase_order,
                                           item=ItemFactory(
                                               material_code='Code 23',
                                               description='Jerrycans'))

        ip_node_one = DeliveryNodeFactory(
            distribution_plan=delivery,
            item=po_item,
            quantity=40,
            tree_position=DistributionPlanNode.IMPLEMENTING_PARTNER,
            delivery_date=FakeDate.build(2015, 03, 19))
        run_one = RunFactory(runnable=ip_node_one)
        quantity_received_qn = NumericQuestion.objects.get(
            label='amountReceived')
        NumericAnswerFactory(question=quantity_received_qn,
                             value=39,
                             run=run_one)

        last_shipment_date = FakeDate.build(2015, 10, 07)
        ip_node_two = DeliveryNodeFactory(
            distribution_plan=delivery,
            item=po_item,
            quantity=30,
            tree_position=DistributionPlanNode.IMPLEMENTING_PARTNER,
            delivery_date=last_shipment_date)
        run_two = RunFactory(runnable=ip_node_two)
        NumericAnswerFactory(question=quantity_received_qn,
                             value=40,
                             run=run_two)

        expected_data = [{
            'document_number':
            purchase_order.order_number,
            'programme':
            programme.name,
            'last_shipment_date':
            str(last_shipment_date),
            'total_value_received':
            Decimal('79'),
            'total_value_dispensed':
            Decimal('0'),
            'balance':
            Decimal('79'),
            'items': [{
                'code': unicode(po_item.item.material_code),
                'description': unicode(po_item.item.description),
                'consignee': self.ip.name,
                'location': ip_node_one.location,
                'quantity_delivered': 3,
                'date_delivered': str(self.ip_node_two.delivery_date),
                'quantity_confirmed': 2,
                'date_confirmed': '2014-01-02',
                'quantity_dispatched': 2,
                'balance': 0
            }, {
                'code': unicode(po_item.item.material_code),
                'description': unicode(po_item.item.description),
                'consignee': self.ip.name,
                'location': ip_node_two.location,
                'quantity_delivered': 5,
                'date_delivered': str(self.ip_node_one.delivery_date),
                'quantity_confirmed': 4,
                'date_confirmed': '2014-01-01',
                'quantity_dispatched': 2,
                'balance': 2
            }]
        }]

        response = self.client.get(ENDPOINT_URL)

        self.assert_api_response_with_correct_last_shipment_date(
            response, expected_data)
Exemplo n.º 7
0
    def test_should_return_node_with_order_number(self):
        po = PurchaseOrderFactory(order_number=123456)
        po_item = PurchaseOrderItemFactory(purchase_order=po)
        node = DeliveryNodeFactory(item=po_item)

        self.assertEqual(node.number(), 123456)
Exemplo n.º 8
0
 def setup_purchase_orders(self):
     self.po_one = PurchaseOrderFactory(sales_order=self.po_one)
     self.po_two = PurchaseOrderFactory(sales_order=self.po_two)
     self.setup_purchase_order_items()
Exemplo n.º 9
0
    def test_returns_correct_balance(self):
        ip = ConsigneeFactory(type=Consignee.TYPES.implementing_partner)

        delivery = DeliveryFactory(consignee=ip, track=True)
        purchase_order = PurchaseOrderFactory()
        po_item = PurchaseOrderItemFactory(purchase_order=purchase_order)
        ip_node_one = DeliveryNodeFactory(
            programme=delivery.programme,
            consignee=ip,
            distribution_plan=delivery,
            item=po_item,
            quantity=40,
            acknowledged=40,
            balance=40,
            tree_position=DistributionPlanNode.IMPLEMENTING_PARTNER)
        ip_node_two = DeliveryNodeFactory(
            programme=delivery.programme,
            consignee=ip,
            distribution_plan=delivery,
            item=po_item,
            quantity=30,
            acknowledged=30,
            balance=30,
            tree_position=DistributionPlanNode.IMPLEMENTING_PARTNER)

        run_one = RunFactory(runnable=ip_node_one)
        run_two = RunFactory(runnable=ip_node_two)

        quantity_received_qn = NumericQuestion.objects.get(
            label='amountReceived')

        NumericAnswerFactory(question=quantity_received_qn,
                             value=40,
                             run=run_one)
        NumericAnswerFactory(question=quantity_received_qn,
                             value=30,
                             run=run_two)

        end_node_one = DeliveryNodeFactory(
            programme=delivery.programme,
            consignee=self.end_user,
            parents=[(ip_node_one, 30), (ip_node_two, 15)],
            tree_position=DistributionPlanNode.END_USER,
            item=po_item)
        end_node_two = DeliveryNodeFactory(
            programme=delivery.programme,
            consignee=self.end_user,
            parents=[(ip_node_one, 5), (ip_node_two, 5)],
            tree_position=DistributionPlanNode.END_USER,
            item=po_item)
        run_end_node_one = RunFactory(runnable=end_node_one)
        run_end_node_two = RunFactory(runnable=end_node_two)

        NumericAnswerFactory(question=quantity_received_qn,
                             value=43,
                             run=run_end_node_one)
        NumericAnswerFactory(question=quantity_received_qn,
                             value=10,
                             run=run_end_node_two)

        endpoint_url = BACKEND_URL + 'stock-report/%s/' % ip.id
        response = self.client.get(endpoint_url)

        expected_data = [{
            'document_number':
            purchase_order.order_number,
            'total_value_received':
            Decimal('700'),
            'total_value_dispensed':
            Decimal('550'),
            'total_value_lost':
            Decimal('0'),
            'balance':
            Decimal('150'),
            'items': [{
                'code': unicode(po_item.item.material_code),
                'description': unicode(po_item.item.description),
                'consignee': ip.name,
                'location': end_node_one.location,
                'quantity_delivered': 30,
                'date_delivered': str(end_node_one.delivery_date),
                'quantity_confirmed': 30,
                'date_confirmed': '',
                'quantity_dispatched': 20,
                'quantity_lost': 0,
                'remark_lost': [],
                'balance': 10
            }, {
                'code': unicode(po_item.item.material_code),
                'description': unicode(po_item.item.description),
                'consignee': ip.name,
                'location': end_node_one.location,
                'quantity_delivered': 40,
                'date_delivered': str(end_node_one.delivery_date),
                'quantity_confirmed': 40,
                'date_confirmed': '',
                'quantity_dispatched': 35,
                'quantity_lost': 0,
                'remark_lost': [],
                'balance': 5
            }]
        }]

        self.assert_api_response(response, expected_data)
Exemplo n.º 10
0
 def test_should_return_empty_list_when_no_deliveries_tied_to_any_purchase_order_items(self):
     order = PurchaseOrderFactory()
     PurchaseOrderItemFactory(purchase_order=order)
     PurchaseOrderItemFactory(purchase_order=order)
     self.assertListEqual(list(order.deliveries()), [])
Exemplo n.º 11
0
 def test_should_know_if_it_has_a_distribution_plan_or_not(self):
     purchase_order = PurchaseOrderFactory()
     purchase_order_item = PurchaseOrderItemFactory(purchase_order=purchase_order)
     self.assertFalse(purchase_order.has_plan())
     NodeFactory(item=purchase_order_item)
     self.assertTrue(purchase_order.has_plan())
Exemplo n.º 12
0
    def setup_nodes_with_answers(self):
        DistributionPlanNode.append_positive_answers = MagicMock(return_value=None)
        ip = ConsigneeFactory(name='ip one')
        middle_man = ConsigneeFactory(name='middle man one', type=Consignee.TYPES.middle_man)
        end_user_one = ConsigneeFactory(name='consignee one', type=Consignee.TYPES.end_user)
        end_user_two = ConsigneeFactory(name='consignee two', type=Consignee.TYPES.end_user)
        programme_one = ProgrammeFactory(name='my first programme')
        programme_two = ProgrammeFactory(name='my second programme')
        programme_three = ProgrammeFactory(name='my third programme')
        purchase_order_item = PurchaseOrderItemFactory(item=ItemFactory(description='Mama kit'),
                                                       purchase_order=PurchaseOrderFactory(order_number=329293))
        release_order_item = ReleaseOrderItemFactory(item=ItemFactory(description='Baba bla bla'),
                                                     release_order=ReleaseOrderFactory(waybill=5540322))

        ip_node_one = DeliveryNodeFactory(consignee=ip, item=purchase_order_item, quantity=1500,
                                          programme=programme_one, track=True,
                                          distribution_plan=DeliveryFactory(track=True),
                                          location='Fort portal', tree_position=Flow.Label.IMPLEMENTING_PARTNER)
        ip_node_two = DeliveryNodeFactory(consignee=ip, item=release_order_item, quantity=100,
                                          distribution_plan=DeliveryFactory(track=True), programme=programme_two,
                                          location='Kampala', tree_position=Flow.Label.IMPLEMENTING_PARTNER, track=True)
        ip_node_three = DeliveryNodeFactory(consignee=ip, item=release_order_item, quantity=100,
                                            distribution_plan=DeliveryFactory(track=True), programme=programme_two,
                                            location='Gulu', tree_position=Flow.Label.IMPLEMENTING_PARTNER, track=True)
        ip_node_four = DeliveryNodeFactory(consignee=ip, item=purchase_order_item, quantity=100,
                                           distribution_plan=DeliveryFactory(track=True), programme=programme_three,
                                           location='Gulu', tree_position=Flow.Label.IMPLEMENTING_PARTNER, track=True)

        middle_man_node = DeliveryNodeFactory(consignee=middle_man, item=purchase_order_item,
                                              programme=programme_one, location='Wakiso', track=True,
                                              tree_position=Flow.Label.MIDDLE_MAN, parents=[(ip_node_one, 1500)],
                                              distribution_plan=None)
        end_user_node_one = DeliveryNodeFactory(consignee=end_user_one,
                                                item=purchase_order_item, parents=[(middle_man_node, 1000)],
                                                programme=programme_one, location='Amuru', track=True,
                                                distribution_plan=None)
        end_user_node_two = DeliveryNodeFactory(consignee=end_user_two, item=purchase_order_item, track=True,
                                                parents=[(middle_man_node, 500)], programme=programme_one,
                                                distribution_plan=None)
        assign_to_self_node = DeliveryNodeFactory(consignee=ip, item=purchase_order_item,
                                                  tree_position=Flow.Label.END_USER, parents=[(ip_node_four, 93)],
                                                  programme=programme_three, distribution_plan=None,
                                                  is_assigned_to_self=True)

        # IP_ITEM Flow and Questions
        ip_item_flow = FlowFactory(label=Flow.Label.IMPLEMENTING_PARTNER)
        ip_item_question_1 = MultipleChoiceQuestionFactory(text='Was the item received?', label='itemReceived',
                                                           when_answered='update_consignee_inventory',
                                                           flow=ip_item_flow, position=1)
        ip_item_option_1 = OptionFactory(text='Yes', question=ip_item_question_1)
        ip_item_option_no = OptionFactory(text='No', question=ip_item_question_1)
        ip_item_question_2 = NumericQuestionFactory(text='How much was received?', label='amountReceived',
                                                    when_answered='update_consignee_stock_level', flow=ip_item_flow,
                                                    position=3)
        ip_item_question_3 = MultipleChoiceQuestionFactory(text='What is the quality of the product?',
                                                           label='qualityOfProduct',
                                                           flow=ip_item_flow, position=3)
        ip_item_option_2 = OptionFactory(text='Good', question=ip_item_question_3)
        ip_item_option_3 = OptionFactory(text='Damaged', question=ip_item_question_3)
        ip_item_question_4 = MultipleChoiceQuestionFactory(text='Are you satisfied with the product?',
                                                           label='satisfiedWithProduct', flow=ip_item_flow, position=4)
        ip_item_option_4 = OptionFactory(text='Yes', question=ip_item_question_4)
        ip_item_option_5 = OptionFactory(text='No', question=ip_item_question_4)

        # MIDDLE_MAN Flow and Questions
        middle_man_flow = FlowFactory(label=Flow.Label.MIDDLE_MAN)
        mm_question_1 = MultipleChoiceQuestionFactory(text='Was product received?', label='productReceived',
                                                      flow=middle_man_flow, position=1)
        mm_option_1 = OptionFactory(text='Yes', question=mm_question_1)
        mm_option_2 = OptionFactory(text='No', question=mm_question_1)
        mm_question_2 = TextQuestionFactory(label='dateOfReceipt', flow=middle_man_flow,
                                            text='When was item received?', position=2)
        mm_question_3 = NumericQuestionFactory(text='What is the amount received?', label='amountReceived',
                                               flow=middle_man_flow, position=3)

        end_user_flow = FlowFactory(label=Flow.Label.END_USER)
        eu_question_1 = MultipleChoiceQuestionFactory(text='Was the item received?', label='itemReceived',
                                                      flow=end_user_flow, position=1)
        eu_option_1 = OptionFactory(text='Yes', question=eu_question_1)
        eu_question_2 = NumericQuestionFactory(text='How much was received?', label='amountReceived',
                                               flow=end_user_flow)
        eu_question_3 = MultipleChoiceQuestionFactory(text='What is the quality of the product?',
                                                      label='qualityOfProduct', flow=end_user_flow, position=3)
        eu_option_3 = OptionFactory(text='Damaged', question=eu_question_3)
        eu_option_3_1 = OptionFactory(text='Good', question=eu_question_3)
        eu_question_4 = MultipleChoiceQuestionFactory(text='Are you satisfied with the product?',
                                                      label='satisfiedWithProduct', flow=end_user_flow, position=4)
        eu_option_4 = OptionFactory(text='Yes', question=eu_question_4)
        eu_question_5 = TextQuestionFactory(label='dateOfReceipt', flow=end_user_flow,
                                            text='When was Delivery Received?')

        ip_run_one = RunFactory(runnable=ip_node_one)
        MultipleChoiceAnswerFactory(question=ip_item_question_1, run=ip_run_one, value=ip_item_option_1)
        NumericAnswerFactory(question=ip_item_question_2, run=ip_run_one, value=1500)
        MultipleChoiceAnswerFactory(question=ip_item_question_3, run=ip_run_one, value=ip_item_option_2)
        MultipleChoiceAnswerFactory(question=ip_item_question_4, run=ip_run_one, value=ip_item_option_4)

        ip_run_three = RunFactory(runnable=ip_node_three)
        MultipleChoiceAnswerFactory(question=ip_item_question_1, run=ip_run_three, value=ip_item_option_no)

        ip_run_two = RunFactory(runnable=ip_node_two)
        MultipleChoiceAnswerFactory(question=ip_item_question_1, run=ip_run_two, value=ip_item_option_1)
        NumericAnswerFactory(question=ip_item_question_2, run=ip_run_two, value=50)
        MultipleChoiceAnswerFactory(question=ip_item_question_3, run=ip_run_two, value=ip_item_option_3)
        MultipleChoiceAnswerFactory(question=ip_item_question_4, run=ip_run_two, value=ip_item_option_5)

        middle_man_node_run = RunFactory(runnable=middle_man_node)
        MultipleChoiceAnswerFactory(question=mm_question_1, run=middle_man_node_run, value=mm_option_1)
        TextAnswerFactory(question=mm_question_2, run=middle_man_node_run, value='2014-9-25')
        NumericAnswerFactory(question=mm_question_3, run=middle_man_node_run, value=1501, remark='Some remark 2')

        end_user_run_one = RunFactory(runnable=end_user_node_one)
        MultipleChoiceAnswerFactory(question=eu_question_1, run=end_user_run_one, value=eu_option_1)
        NumericAnswerFactory(question=eu_question_2, run=end_user_run_one, value=5)
        MultipleChoiceAnswerFactory(question=eu_question_3, run=end_user_run_one, value=eu_option_3)
        MultipleChoiceAnswerFactory(question=eu_question_4, run=end_user_run_one, value=eu_option_4)
        TextAnswerFactory(run=end_user_run_one, question=eu_question_5, value='2014-10-10')

        end_user_run_two = RunFactory(runnable=end_user_node_two)
        MultipleChoiceAnswerFactory(question=eu_question_1, run=end_user_run_two, value=eu_option_1)
        NumericAnswerFactory(question=eu_question_2, run=end_user_run_two, value=500)
        MultipleChoiceAnswerFactory(question=eu_question_3, run=end_user_run_two, value=eu_option_3)
        MultipleChoiceAnswerFactory(question=eu_question_4, run=end_user_run_two, value=eu_option_4)
        TextAnswerFactory(question=eu_question_5, run=end_user_run_two, value='2013-12-12')

        assign_to_self_run = RunFactory(runnable=assign_to_self_node)
        MultipleChoiceAnswerFactory(question=eu_question_1, run=assign_to_self_run, value=eu_option_1)
        NumericAnswerFactory(question=eu_question_2, run=assign_to_self_run, value=500)
        TextAnswerFactory(question=eu_question_5, run=assign_to_self_run, value='2013-12-14')
        MultipleChoiceAnswerFactory(question=eu_question_3, run=assign_to_self_run, value=eu_option_3_1)
        MultipleChoiceAnswerFactory(question=eu_question_4, run=assign_to_self_run, value=eu_option_4)

        return end_user_node_one, purchase_order_item, release_order_item, end_user_node_two, ip_node_two, ip, assign_to_self_node
Exemplo n.º 13
0
 def test_should_return_empty_list_when_no_deliveries_tied_to_any_purchase_order_items(
         self):
     order = PurchaseOrderFactory()
     PurchaseOrderItemFactory(purchase_order=order)
     PurchaseOrderItemFactory(purchase_order=order)
     self.assertListEqual(list(order.deliveries()), [])
Exemplo n.º 14
0
 def test_no_two_purchase_orders_should_have_the_same_order_number(self):
     create_purchase_order = lambda: PurchaseOrderFactory(order_number=1234)
     create_purchase_order()
     self.assertRaises(IntegrityError, create_purchase_order)
Exemplo n.º 15
0
 def test_should_know_if_it_has_a_distribution_plan_or_not(self):
     purchase_order = PurchaseOrderFactory()
     purchase_order_item = PurchaseOrderItemFactory(purchase_order=purchase_order)
     self.assertFalse(purchase_order.has_plan())
     NodeFactory(item=purchase_order_item)
     self.assertTrue(purchase_order.has_plan())
Exemplo n.º 16
0
 def test_should_show_total_quantity_as_balance_when_no_nodes_exist(self):
     purchase_order = PurchaseOrderFactory()
     purchase_order_item = PurchaseOrderItemFactory(
         purchase_order=purchase_order, quantity=500)
     self.assertEquals(purchase_order_item.available_balance(), 500)
Exemplo n.º 17
0
 def test_should_return_type(self):
     purchase_order = PurchaseOrderFactory()
     purchase_order_item = PurchaseOrderItemFactory(
         purchase_order=purchase_order)
     self.assertEqual(purchase_order_item.type(), "Purchase Order")