Ejemplo n.º 1
0
 def test_adjust_pennies(self):
     amts = [Decimal('-13.33'), Decimal('-13.33'), Decimal('-13.33')]
     costs = [Decimal('173.33'), Decimal('173.34'), Decimal('173.34')]
     expected_amts = [Decimal('-13.33'), Decimal('-13.33'), Decimal('-13.34')]
     expected_costs = [Decimal('173.33'), Decimal('173.33'), Decimal('173.34')]
     lst = [(Decimal('-40'), amts), (Decimal('520'), costs)]
     from efms.utils import adjust_pennies
     adjust_pennies(lst)
     self.assertListEqual(expected_amts, amts)
     self.assertListEqual(expected_costs, costs)
Ejemplo n.º 2
0
def new_allocations(txn_amt, ancestor):
    allocs = ([], [], [])
    totals = [Decimal(0), Decimal(0)]
    ancestor_allocations = ancestor.allocations.all()
    for prj_item in ancestor_allocations:
        allocs[0].append(prj_item.account_id)
        percent = prj_item.cost / ancestor.cost
        cost = utils.to_money((ancestor.cost + txn_amt) * percent)
        amt = utils.to_money(txn_amt * percent)
        totals[0] += amt
        totals[1] += cost
        allocs[1].append(amt)
        allocs[2].append(cost)
    if ancestor.unallocated_amt == 0 and totals[0] != txn_amt:
        utils.adjust_pennies([(txn_amt, allocs[1]), (ancestor.cost + txn_amt, allocs[2])])
    return [Allocation(acct, amt, cost) for acct, amt, cost in zip(allocs[0], allocs[1], allocs[2])]