Exemplo n.º 1
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,
            tree_position=DistributionPlanNode.IMPLEMENTING_PARTNER)
        self.assertFalse(purchase_order.is_fully_delivered())

        node_two = NodeFactory(
            item=item_two,
            quantity=100,
            distribution_plan=delivery,
            tree_position=DistributionPlanNode.IMPLEMENTING_PARTNER)
        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.º 2
0
    def pair_tracked_date_on_updated(self, pre_purchase_order_tracked_date=None, delivery_tracked_date=None):
        purchase_order = PurchaseOrderFactory(tracked_date=pre_purchase_order_tracked_date)
        po_item = PurchaseOrderItemFactory(purchase_order=purchase_order)
        delivery = DeliveryFactory(track=True, tracked_date=delivery_tracked_date)
        DeliveryNodeFactory(distribution_plan=delivery, item=po_item)
        delivery.save()

        updated_tracked_date = PurchaseOrder.objects.get(pk=purchase_order.id).tracked_date
        return updated_tracked_date
Exemplo n.º 3
0
    def test_balance_should_decrease_when_tracked_nodes_exist(self):
        purchase_order_item = PurchaseOrderItemFactory(purchase_order=(PurchaseOrderFactory()), quantity=500)

        delivery = DeliveryFactory()
        node_one = NodeFactory(item=purchase_order_item, quantity=200, distribution_plan=delivery)
        self.assertEquals(purchase_order_item.available_balance(), 500)

        delivery.track = True
        delivery.save()
        self.assertEquals(purchase_order_item.available_balance(), 300)

        NodeFactory(item=purchase_order_item, quantity=120, distribution_plan=delivery)

        self.assertEquals(purchase_order_item.available_balance(), 180)
Exemplo n.º 4
0
    def pair_tracked_date_on_updated(self,
                                     pre_purchase_order_tracked_date=None,
                                     delivery_tracked_date=None):
        purchase_order = PurchaseOrderFactory(
            tracked_date=pre_purchase_order_tracked_date)
        po_item = PurchaseOrderItemFactory(purchase_order=purchase_order)
        delivery = DeliveryFactory(track=True,
                                   tracked_date=delivery_tracked_date)
        DeliveryNodeFactory(distribution_plan=delivery, item=po_item)
        delivery.save()

        updated_tracked_date = PurchaseOrder.objects.get(
            pk=purchase_order.id).tracked_date
        return updated_tracked_date
Exemplo n.º 5
0
    def test_should_decrease_balance_when_saving_tracked_or_not_tracked_nodes(self):
        purchase_order_item = PurchaseOrderItemFactory(quantity=500)

        delivery = DeliveryFactory()
        DeliveryNodeFactory(item=purchase_order_item, quantity=200, distribution_plan=delivery)
        self.assertEquals(purchase_order_item.available_balance(), 300)
        self.assertEquals(purchase_order_item.quantity_shipped(), 200)

        delivery.track = True
        delivery.save()
        self.assertEquals(purchase_order_item.available_balance(), 300)
        self.assertEquals(purchase_order_item.quantity_shipped(), 200)

        tracked_delivery = DeliveryFactory(track=True)
        DeliveryNodeFactory(item=purchase_order_item, quantity=120, distribution_plan=tracked_delivery)
        self.assertEquals(purchase_order_item.available_balance(), 180)
        self.assertEquals(purchase_order_item.quantity_shipped(), 320)
Exemplo n.º 6
0
    def test_should_mirror_delivery_tracked_status_on_all_nodes_when_tracked_status_changes_on_delivery(self):
        Delivery.objects.all().delete()
        delivery = DeliveryFactory(track=False)
        root_node = DeliveryNodeFactory(distribution_plan=delivery)
        child_node = DeliveryNodeFactory(distribution_plan=delivery, parents=[(root_node, 5)])

        self.assertFalse(root_node.track)
        self.assertFalse(child_node.track)

        delivery.track = True
        delivery.save()
        self.assertTrue(DeliveryNode.objects.get(pk=root_node.id).track)
        self.assertTrue(DeliveryNode.objects.get(pk=child_node.id).track)

        delivery.track = False
        delivery.save()
        self.assertFalse(DeliveryNode.objects.get(pk=root_node.id).track)
        self.assertFalse(DeliveryNode.objects.get(pk=child_node.id).track)
Exemplo n.º 7
0
    def test_balance_should_decrease_when_tracked_nodes_exist(self):
        purchase_order_item = PurchaseOrderItemFactory(quantity=500)

        delivery = DeliveryFactory()
        NodeFactory(item=purchase_order_item,
                    quantity=200,
                    distribution_plan=delivery)
        self.assertEquals(purchase_order_item.available_balance(), 500)

        delivery.track = True
        delivery.save()
        self.assertEquals(purchase_order_item.available_balance(), 300)

        NodeFactory(item=purchase_order_item,
                    quantity=120,
                    distribution_plan=delivery)

        self.assertEquals(purchase_order_item.available_balance(), 180)
Exemplo n.º 8
0
    def test_should_mirror_delivery_tracked_status_on_all_nodes_when_tracked_status_changes_on_delivery(
            self):
        Delivery.objects.all().delete()
        delivery = DeliveryFactory(track=False)
        root_node = DeliveryNodeFactory(distribution_plan=delivery)
        child_node = DeliveryNodeFactory(distribution_plan=delivery,
                                         parents=[(root_node, 5)])

        self.assertFalse(root_node.track)
        self.assertFalse(child_node.track)

        delivery.track = True
        delivery.save()
        self.assertTrue(DeliveryNode.objects.get(pk=root_node.id).track)
        self.assertTrue(DeliveryNode.objects.get(pk=child_node.id).track)

        delivery.track = False
        delivery.save()
        self.assertFalse(DeliveryNode.objects.get(pk=root_node.id).track)
        self.assertFalse(DeliveryNode.objects.get(pk=child_node.id).track)
Exemplo n.º 9
0
    def test_should_decrease_balance_when_saving_tracked_or_not_tracked_nodes(
            self):
        purchase_order_item = PurchaseOrderItemFactory(quantity=500)

        delivery = DeliveryFactory()
        DeliveryNodeFactory(item=purchase_order_item,
                            quantity=200,
                            distribution_plan=delivery)
        self.assertEquals(purchase_order_item.available_balance(), 300)
        self.assertEquals(purchase_order_item.quantity_shipped(), 200)

        delivery.track = True
        delivery.save()
        self.assertEquals(purchase_order_item.available_balance(), 300)
        self.assertEquals(purchase_order_item.quantity_shipped(), 200)

        tracked_delivery = DeliveryFactory(track=True)
        DeliveryNodeFactory(item=purchase_order_item,
                            quantity=120,
                            distribution_plan=tracked_delivery)
        self.assertEquals(purchase_order_item.available_balance(), 180)
        self.assertEquals(purchase_order_item.quantity_shipped(), 320)
Exemplo n.º 10
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())