Example #1
0
 def test_should_take_multiple_losses_into_account_when_calculating_balance(
         self):
     node = DeliveryNodeFactory(acknowledged=50)
     DeliveryNodeLossFactory(quantity=10, delivery_node=node)
     DeliveryNodeLossFactory(quantity=25, delivery_node=node)
     node.save()
     self.assertEqual(node.balance, 15)
Example #2
0
    def test_should_create_a_loss_associated_with_particular_node(self):
        delivery_node = DeliveryNodeFactory()
        DeliveryNodeLossFactory(quantity=10,
                                remark='building fire',
                                delivery_node=delivery_node)
        DeliveryNodeLossFactory(quantity=5,
                                remark='building down',
                                delivery_node=delivery_node)

        self.assertEqual(delivery_node.losses.count(), 2)
        self.assertEqual(delivery_node.losses.first().quantity, 10)
        self.assertEqual(delivery_node.losses.first().remark, 'building fire')
        self.assertEqual(delivery_node.losses.last().quantity, 5)
        self.assertEqual(delivery_node.losses.last().remark, 'building down')
Example #3
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)
Example #4
0
    def setup_nodes(self):
        self.ip_node_one = DeliveryNodeFactory(
            distribution_plan=self.plan_one,
            consignee=self.ip,
            tree_position=DistributionPlanNode.IMPLEMENTING_PARTNER,
            item=self.po_item_one,
            quantity=15)
        self.ip_node_two = DeliveryNodeFactory(
            distribution_plan=self.plan_two,
            consignee=self.ip,
            tree_position=DistributionPlanNode.IMPLEMENTING_PARTNER,
            item=self.po_item_two,
            quantity=3)
        self.ip_node_three = DeliveryNodeFactory(
            distribution_plan=self.plan_three,
            consignee=self.ip,
            tree_position=DistributionPlanNode.IMPLEMENTING_PARTNER,
            item=self.po_item_three,
            quantity=2)

        self.middle_man_node_one = DeliveryNodeFactory(
            consignee=self.middle_man_one,
            programme=self.plan_one.programme,
            tree_position=DistributionPlanNode.MIDDLE_MAN,
            parents=[(self.ip_node_one, 2)],
            item=self.po_item_one)
        self.middle_man_node_two = DeliveryNodeFactory(
            consignee=self.middle_man_two,
            programme=self.plan_two.programme,
            tree_position=DistributionPlanNode.MIDDLE_MAN,
            parents=[(self.ip_node_two, 2)],
            item=self.po_item_two)
        self.end_user_node = DeliveryNodeFactory(
            consignee=self.end_user,
            programme=self.plan_three.programme,
            tree_position=DistributionPlanNode.END_USER,
            parents=[(self.ip_node_three, 2)],
            item=self.po_item_three)

        self.ip_node_one_loss = DeliveryNodeLossFactory(
            quantity=3, delivery_node=self.ip_node_one)