def test_set_cost(self): ancestor_cost = Decimal('560') item = ControlPointLineItem() item.txn_type = 'A' item.txn_amt = Decimal('-40') item._set_cost(ancestor_cost) self.assertEquals(Decimal('520'), item.cost)
def test_set_unallocated_amt(self): item = ControlPointLineItem() item.cost = Decimal('12368') costs = [Decimal('1236.8'), Decimal('6184'), Decimal('3092')] item._set_unallocated_amt(costs) self.assertEquals(Decimal('1855.2'), item.unallocated_amt) item.cost = Decimal('11161') costs = [Decimal('1116.1'), Decimal('5580.5'), Decimal('2790.25')] item._set_unallocated_amt(costs) self.assertEquals(Decimal('1674.15'), item.unallocated_amt) item.cost = Decimal('18403') costs = [Decimal('1840.3'), Decimal('9201.5'), Decimal('4600.75')] item._set_unallocated_amt(costs) self.assertEquals(Decimal('2760.45'), item.unallocated_amt)
def create_cp_1382_12_items_partial(): """ Saves to DB part of control point 666-12. Simulates state after new FMS items have been saved and an OBL has been allocated from which ADJs in a subsequent report will inherit. """ cp = create_cp_1382_12() item = ControlPointLineItem() item.id = 1 item.ien = '96224134' item.fyqseq = '1210001' item.txn_type = 'CA' item.description = u'None' cp.line_items.add(item) item = ControlPointLineItem() item.id = 2 item.ien = '96224118' item.fyqseq = '1210002' item.txn_type = 'O' item.obl_nbr = 'D27012' item.txn_amt = Decimal('6666') item.unallocated_amt = item.txn_amt item.cost = item.txn_amt item.description = u'None' cp.line_items.add(item) item = ControlPointLineItem() item.id = 3 item.ien = '96041404' item.fyqseq = '1210009' item.txn_type = 'CA' cp.line_items.add(item) item = ControlPointLineItem() item.id = 4 item.ien = '95958457' item.fyqseq = '1210011' item.txn_type = 'O' item.obl_nbr = 'D25011' item.obl_date = '2011-10-03' item.txn_amt = Decimal('560') item.unallocated_amt = item.txn_amt item.cost = item.txn_amt item.unallocated_amt = Decimal(0) item.description = u'Case of the screaming meemies' cp.line_items.add(item) allocate_D25011_OBL() item = ControlPointLineItem() item.id = 5 item.ien = '95877740' item.fyqseq = '1210021' item.txn_type = 'O' item.obl_nbr = 'D25025' item.txn_amt = Decimal('12368') item.unallocated_amt = item.txn_amt item.cost = item.txn_amt item.description = u'None' cp.line_items.add(item) cp.save()
def create_items_both_cps_with_allocs(): """ Saves all of the line items from both control points to the DB. Used to setup cross-control point inheritance tests. """ cp = create_cp_1382_12() item = ControlPointLineItem() item.id = 1 item.ien = '96224134' item.fyqseq = '1210001' item.txn_type = 'CA' item.description = u'1210001:CAN:' cp.line_items.add(item) item = ControlPointLineItem() item.id = 2 item.ien = '96224118' item.fyqseq = '1210002' item.txn_type = 'O' item.obl_nbr = 'D27012' item.txn_amt = Decimal('6666') item.cost = item.txn_amt item.description = u'1210002:OBL:D27012' cp.line_items.add(item) item = ControlPointLineItem() item.id = 3 item.ien = '96041404' item.fyqseq = '1210009' item.txn_type = 'CA' cp.line_items.add(item) item = ControlPointLineItem() item.id = 4 item.ien = '95958457' item.fyqseq = '1210011' item.txn_type = 'O' item.obl_nbr = 'D25011' item.obl_date = '2011-10-03' item.txn_amt = Decimal('560') item.cost = item.txn_amt item.unallocated_amt = Decimal(0) item.description = u'1210011:OBL:D25011' cp.line_items.add(item) item = ControlPointLineItem() item.id = 5 item.ien = '95877740' item.fyqseq = '1210021' item.txn_type = 'O' item.obl_nbr = 'D25025' item.txn_amt = Decimal('12368') item.cost = item.txn_amt item.description = u'1210021:OBL:D25025' cp.line_items.add(item) item = ControlPointLineItem() item.id = 6 item.ien = '95876936' item.fyqseq = '1210029' item.txn_type = 'A' item.obl_nbr = 'D25011' item.obl_date = '2011-10-31' item.txn_amt = Decimal('-40') item.description = u'1210029:ADJ:D25011' cp.line_items.add(item) item = ControlPointLineItem() item.id = 7 item.ien = '95873815' item.fyqseq = '1210033' item.txn_type = 'A' item.obl_nbr = 'D25011' item.obl_date = '2011-11-25' item.txn_amt = Decimal('-240') item.description = u'1210033:ADJ:D25011' cp.line_items.add(item) allocate_D25011_all() item = ControlPointLineItem() item.id = 8 item.ien = '95871250' item.fyqseq = '1210038' item.txn_type = 'C' item.obl_nbr = '506FC9276' item.txn_amt = Decimal('157655') item.description = u'1210038:CEI:506FC9276' cp.line_items.add(item) item = ControlPointLineItem() item.id = 9 item.ien = '95870938' item.fyqseq = '1210043' item.txn_type = 'A' item.obl_nbr = 'D25025' item.txn_amt = Decimal('-1207') item.description = u'1210043:ADJ:D25025' cp.line_items.add(item) item = ControlPointLineItem() item.id = 10 item.ien = '95864913' item.fyqseq = '1220062' item.txn_type = 'A' item.obl_nbr = 'QTRADJ' item.txn_amt = Decimal('50') item.description = u'1220062:ADJ:QTRADJ' cp.line_items.add(item) item = ControlPointLineItem() item.id = 11 item.ien = '95857527' item.fyqseq = '1220076' item.txn_type = 'A' item.obl_nbr = 'D25025' item.txn_amt = Decimal('7242') item.description = u'1220076:ADJ:D25025' cp.line_items.add(item) item = ControlPointLineItem() item.id = 12 item.ien = '95817232' item.fyqseq = '1230155' item.txn_type = 'A' item.obl_nbr = 'D25025' item.txn_amt = Decimal('7242') item.description = u'1230155:ADJ:D25025' cp.line_items.add(item) item = ControlPointLineItem() item.id = 13 item.ien = '95765346' item.fyqseq = '1230232' item.txn_type = 'O' item.obl_nbr = 'R24911' item.txn_amt = Decimal('364.28') item.cost = item.txn_amt item.description = u'1230232:OBL:R24911' cp.line_items.add(item) item = ControlPointLineItem() item.id = 14 item.ien = '95720469' item.fyqseq = '1240304' item.txn_type = 'A' item.obl_nbr = 'B0523F' item.txn_amt = Decimal('176472') item.description = u'1240304:ADJ:B0523F' cp.line_items.add(item) item = ControlPointLineItem() item.id = 15 item.ien = '95718275' item.fyqseq = '1240311' item.txn_type = 'A' item.obl_nbr = 'D25025' item.txn_amt = Decimal('-281.99') item.description = u'1240311:ADJ:D25025' cp.line_items.add(item) cp.save() cp = create_cp_1382_13() item = ControlPointLineItem() item.id = 16 item.ien = '95434961' item.fyqseq = '1240637' item.txn_type = 'A' item.obl_nbr = 'D25025' item.txn_amt = Decimal('874.86') item.description = u'1240637:ADJ:D25025' cp.line_items.add(item) item = ControlPointLineItem() item.id = 17 item.ien = '95432617' item.fyqseq = '1240640' item.txn_type = 'A' item.obl_nbr = 'D25025' item.txn_amt = Decimal('-40.00') item.description = u'1240640:ADJ:D25025' cp.line_items.add(item) item = ControlPointLineItem() item.id = 18 item.ien = '95436544' item.fyqseq = '1310003' item.txn_type = 'A' item.obl_nbr = 'ADJ002' item.txn_amt = Decimal('-8469.86') item.description = u'1310003:ADJ:ADJ002' cp.line_items.add(item) cp.save()
def create_cp_1382_12_items_whole_no_allocs(): """ Saves all of the line items for control point 666-12 to the DB. Used to test bequeathing. """ cp = create_cp_1382_12() item = ControlPointLineItem() item.id = 1 item.ien = '96224134' item.fyqseq = '1210001' item.txn_type = 'CA' item.description = u'1210001:CAN:' cp.line_items.add(item) item = ControlPointLineItem() item.id = 2 item.ien = '96224118' item.fyqseq = '1210002' item.txn_type = 'O' item.obl_nbr = 'D27012' item.txn_amt = Decimal('6666') item.cost = item.txn_amt item.description = u'1210002:OBL:D27012' cp.line_items.add(item) item = ControlPointLineItem() item.id = 3 item.ien = '96041404' item.fyqseq = '1210009' item.txn_type = 'CA' cp.line_items.add(item) item = ControlPointLineItem() item.id = 4 item.ien = '95958457' item.fyqseq = '1210011' item.txn_type = 'O' item.obl_nbr = 'D25011' item.obl_date = '2011-10-03' item.txn_amt = Decimal('560') item.cost = item.txn_amt item.description = u'1210011:OBL:D25011' cp.line_items.add(item) item = ControlPointLineItem() item.id = 5 item.ien = '95877740' item.fyqseq = '1210021' item.txn_type = 'O' item.obl_nbr = 'D25025' item.txn_amt = Decimal('12368') item.cost = item.txn_amt item.description = u'1210021:OBL:D25025' cp.line_items.add(item) item = ControlPointLineItem() item.id = 6 item.ien = '95876936' item.fyqseq = '1210029' item.txn_type = 'A' item.obl_nbr = 'D25011' item.obl_date = '2011-10-31' item.txn_amt = Decimal('-40') item.description = u'1210029:ADJ:D25011' cp.line_items.add(item) item = ControlPointLineItem() item.id = 7 item.ien = '95873815' item.fyqseq = '1210033' item.txn_type = 'A' item.obl_nbr = 'D25011' item.obl_date = '2011-11-25' item.txn_amt = Decimal('-240') item.description = u'1210033:ADJ:D25011' cp.line_items.add(item) item = ControlPointLineItem() item.id = 8 item.ien = '95871250' item.fyqseq = '1210038' item.txn_type = 'C' item.obl_nbr = '506FC9276' item.txn_amt = Decimal('157655') item.description = u'1210038:CEI:506FC9276' cp.line_items.add(item) item = ControlPointLineItem() item.id = 9 item.ien = '95870938' item.fyqseq = '1210043' item.txn_type = 'A' item.obl_nbr = 'D25025' item.txn_amt = Decimal('-1207') item.description = u'1210043:ADJ:D25025' cp.line_items.add(item) item = ControlPointLineItem() item.id = 10 item.ien = '95864913' item.fyqseq = '1220062' item.txn_type = 'A' item.obl_nbr = 'QTRADJ' item.txn_amt = Decimal('50') item.description = u'1220062:ADJ:QTRADJ' cp.line_items.add(item) item = ControlPointLineItem() item.id = 11 item.ien = '95857527' item.fyqseq = '1220076' item.txn_type = 'A' item.obl_nbr = 'D25025' item.txn_amt = Decimal('7242') item.description = u'1220076:ADJ:D25025' cp.line_items.add(item) item = ControlPointLineItem() item.id = 12 item.ien = '95817232' item.fyqseq = '1230155' item.txn_type = 'A' item.obl_nbr = 'D25025' item.txn_amt = Decimal('7242') item.description = u'1230155:ADJ:D25025' cp.line_items.add(item) item = ControlPointLineItem() item.id = 13 item.ien = '95765346' item.fyqseq = '1230232' item.txn_type = 'O' item.obl_nbr = 'R24911' item.txn_amt = Decimal('364.28') item.cost = item.txn_amt item.description = u'1230232:OBL:R24911' cp.line_items.add(item) item = ControlPointLineItem() item.id = 14 item.ien = '95720469' item.fyqseq = '1240304' item.txn_type = 'A' item.obl_nbr = 'B0523F' item.txn_amt = Decimal('176472') item.description = u'1240304:ADJ:B0523F' cp.line_items.add(item) item = ControlPointLineItem() item.id = 15 item.ien = '95718275' item.fyqseq = '1240311' item.txn_type = 'A' item.obl_nbr = 'D25025' item.txn_amt = Decimal('-281.99') item.description = u'1240311:ADJ:D25025' cp.line_items.add(item) cp.save()
def test_inherit_total_evenly_allocated(self): create_cp_1382_12_items_partial() cp = ControlPoint.objects.get(slug='1382-12') ancestor = ControlPointLineItem.objects.get(ien='95958457') ancestor.cost = Decimal('560') item = ControlPointLineItem() item.id = 6 item.ien = '95876936' item.fyqseq = '1210029' item.txn_type = 'A' item.obl_nbr = 'D25011' item.obl_date = '2011-10-31' item.txn_amt = Decimal('-40') item.description = u'None' item.control_point = cp item._inherit(ancestor) self.assertEquals(ancestor.description, item.description) self.assertEquals(ancestor.unallocated_amt, item.unallocated_amt) self.assertEquals(Decimal('520'), item.cost) self.assertEquals(ancestor.allocations.count(), item.allocations.count()) total_amt = Decimal(0) total_cost = Decimal(0) for ancestor_alloc, item_alloc in zip(ancestor.allocations.all(), item.allocations.all()): self.assertEquals(ancestor_alloc.account_id, item_alloc.account_id) self.assertTrue(item_alloc.amount in [Decimal('-13.33'), Decimal('-13.34')]) total_amt += item_alloc.amount self.assertTrue(item_alloc.cost in [Decimal('173.33'), Decimal('173.34')]) total_cost += item_alloc.cost self.assertEquals(item.txn_amt, total_amt) self.assertEquals(item.cost, total_cost) ancestor = item item = ControlPointLineItem() item.id = 7 item.ien = '95873815' item.fyqseq = '1210033' item.txn_type = 'A' item.obl_nbr = 'D25011' item.obl_date = '2011-11-25' item.txn_amt = Decimal('-240') item.description = u'None' item.control_point = cp item._inherit(ancestor) self.assertEquals(ancestor.description, item.description) self.assertEquals(ancestor.unallocated_amt, item.unallocated_amt) self.assertEquals(Decimal('280'), item.cost) self.assertEquals(ancestor.allocations.count(), item.allocations.count()) total_amt = Decimal(0) total_cost = Decimal(0) for ancestor_alloc, item_alloc in zip(ancestor.allocations.all(), item.allocations.all()): self.assertEquals(ancestor_alloc.account_id, item_alloc.account_id) self.assertEquals(Decimal('-80'), item_alloc.amount) total_amt += item_alloc.amount self.assertTrue(item_alloc.cost in [Decimal('93.33'), Decimal('93.34')]) total_cost += item_alloc.cost self.assertEquals(item.txn_amt, total_amt) self.assertEquals(item.cost, total_cost)
def test_is_descendent(self): item = ControlPointLineItem() item.txn_type = 'C' self.assertFalse(item._is_descendent()) item.txn_type = 'CA' self.assertFalse(item._is_descendent()) item.txn_type = 'A' item.obl_nbr = 'QTRADJ' self.assertFalse(item._is_descendent()) item.txn_type = 'A' item.obl_nbr = 'ADJ002' self.assertFalse(item._is_descendent()) item.txn_type = 'A' item.obl_nbr = 'P2345' self.assertTrue(item._is_descendent()) item.txn_type = 'A' item.obl_nbr = 'R98943-1' self.assertTrue(item._is_descendent()) item.txn_type = 'O' self.assertFalse(item._is_descendent())