Example #1
0
 def test_cluster_ticket_delete(self):
     ticket1 = Ticket.objects.create(summary='one', topic=self.topic, rating_percentage=100)
     ticket1.add_acks('content', 'docs', 'archive')
     tid1 = ticket1.id
     Expediture.objects.create(ticket_id=tid1, description='exp', amount=100)
     
     # pay ticket with one transaction
     tr1 = Transaction.objects.create(date=datetime.date(2011, 12, 25), amount=100, other=self.user, description='pay1')
     tr1.tickets.add(ticket1)
     self.assertEqual('paid', Ticket.objects.get(id=tid1).payment_status)
     self.assertEqual(FinanceStatus(paid=100), self.topic.payment_summary())
     self.assertEqual({'unpaid':0, 'paid':100, 'overpaid':0}, Cluster.cluster_sums())
     
     # add another ticket to the transaction cluster
     ticket2 = Ticket.objects.create(summary='two', topic=self.topic, rating_percentage=100)
     ticket2.add_acks('content', 'docs', 'archive')
     Expediture.objects.create(ticket_id=ticket2.id, description='exp', amount=50)
     tr1.tickets.add(ticket2)
     self.assertEqual('partially_paid', Ticket.objects.get(id=tid1).payment_status)
     self.assertEqual('partially_paid', Ticket.objects.get(id=tid1).payment_status)
     self.assertEqual(FinanceStatus(unpaid=50, paid=100), self.topic.payment_summary())
     self.assertEqual({'unpaid':50, 'paid':100, 'overpaid':0}, Cluster.cluster_sums())
     
     # delete tr2 to make ticket 'paid' again
     ticket2.delete()
     self.assertEqual('paid', Ticket.objects.get(id=tid1).payment_status)
     self.assertEqual(FinanceStatus(paid=100), self.topic.payment_summary())
     self.assertEqual({'unpaid':0, 'paid':100, 'overpaid':0}, Cluster.cluster_sums())
Example #2
0
 def test_simple_ticket(self):
     ticket = Ticket.objects.create(summary='foo', topic=self.topic, rating_percentage=100)
     ticket.add_acks('content')
     tid = ticket.id
     self.assertEqual('n_a', Ticket.objects.get(id=tid).payment_status)
     
     ticket.add_acks('docs', 'archive')
     self.assertEqual('n_a', Ticket.objects.get(id=tid).payment_status)
     self.assertEqual(FinanceStatus(), self.topic.payment_summary())
     self.assertEqual({'unpaid':0, 'paid':0, 'overpaid':0}, Cluster.cluster_sums())
     
     Expediture.objects.create(ticket_id=tid, description='exp', amount=100)
     self.assertEqual('unpaid', Ticket.objects.get(id=tid).payment_status)
     self.assertEqual(FinanceStatus(unpaid=100), self.topic.payment_summary())
     self.assertEqual({'unpaid':100, 'paid':0, 'overpaid':0}, Cluster.cluster_sums())
     
     tr = Transaction.objects.create(date=datetime.date(2011, 12, 24), amount=50, other=self.user, description='part one')
     tr.tickets.add(ticket)
     self.assertEqual('partially_paid', Ticket.objects.get(id=tid).payment_status)
     self.assertEqual(FinanceStatus(unpaid=50, paid=50), self.topic.payment_summary())
     self.assertEqual({'unpaid':50, 'paid':50, 'overpaid':0}, Cluster.cluster_sums())
     
     tr = Transaction.objects.create(date=datetime.date(2011, 12, 25), amount=50, other=self.user, description='part one')
     tr.tickets.add(ticket)
     self.assertEqual('paid', Ticket.objects.get(id=tid).payment_status)
     self.assertEqual(FinanceStatus(paid=100), self.topic.payment_summary())
     self.assertEqual({'unpaid':0, 'paid':100, 'overpaid':0}, Cluster.cluster_sums())
     
     tr = Transaction.objects.create(date=datetime.date(2011, 12, 26), amount=50, other=self.user, description='overkill')
     tr.tickets.add(ticket)
     self.assertEqual('overpaid', Ticket.objects.get(id=tid).payment_status)
     self.assertEqual(FinanceStatus(paid=100, overpaid=50), self.topic.payment_summary())
     self.assertEqual({'unpaid':0, 'paid':100, 'overpaid':50}, Cluster.cluster_sums())
     
     c = Ticket.objects.get(id=tid).cluster
     self.assertEqual(tid, c.id)
     self.assertEqual(False, c.more_tickets)
     self.assertEqual(100, c.total_tickets)
     self.assertEqual(150, c.total_transactions)
Example #3
0
 def test_cluster_transaction_delete(self):
     ticket = Ticket.objects.create(summary='one', topic=self.topic, rating_percentage=100)
     ticket.add_acks('content', 'docs', 'archive')
     tid = ticket.id
     Expediture.objects.create(ticket_id=tid, description='exp', amount=100)
     
     tr1 = Transaction.objects.create(date=datetime.date(2011, 12, 24), amount=100, other=self.user, description='pay1')
     tr1.tickets.add(ticket)
     self.assertEqual('paid', Ticket.objects.get(id=tid).payment_status)
     self.assertEqual(FinanceStatus(paid=100), self.topic.payment_summary())
     self.assertEqual({'unpaid':0, 'paid':100, 'overpaid':0}, Cluster.cluster_sums())
     
     tr2 = Transaction.objects.create(date=datetime.date(2011, 12, 25), amount=5, other=self.user, description='pay1plus')
     tr2.tickets.add(ticket)
     self.assertEqual('overpaid', Ticket.objects.get(id=tid).payment_status)
     self.assertEqual(FinanceStatus(paid=100, overpaid=5), self.topic.payment_summary())
     self.assertEqual({'unpaid':0, 'paid':100, 'overpaid':5}, Cluster.cluster_sums())
     
     # delete tr2 to make ticket 'paid' again
     tr2.delete()
     self.assertEqual('paid', Ticket.objects.get(id=tid).payment_status)
     self.assertEqual(FinanceStatus(paid=100), self.topic.payment_summary())
     self.assertEqual({'unpaid':0, 'paid':100, 'overpaid':0}, Cluster.cluster_sums())
Example #4
0
def topic_finance(request):
    grants_out = []
    for grant in Grant.objects.all():
        topics = []
        grant_finance = FinanceStatus()
        for topic in grant.topic_set.all():
            topic_finance = topic.payment_summary()
            grant_finance.add_finance(topic_finance)
            topics.append({'topic':topic, 'finance':topic_finance})
        grants_out.append({'grant':grant, 'topics':topics, 'finance':grant_finance, 'rows':len(topics)+1})
    
    csums = Cluster.cluster_sums()
    return render(request, 'tracker/topic_finance.html', {
        'grants': grants_out,
        'cluster_sums': csums,
        'total_transactions': csums['paid'] + csums['overpaid'], 
        'have_fuzzy': any([row['finance'].fuzzy for row in grants_out]),
    })  
Example #5
0
 def test_fuzzy_cluster(self):
     ticket1 = Ticket.objects.create(summary='one', topic=self.topic, rating_percentage=100)
     ticket1.add_acks('content', 'docs', 'archive')
     Expediture.objects.create(ticket_id=ticket1.id, description='exp', amount=100)
     
     ticket2 = Ticket.objects.create(summary='two', topic=self.topic, rating_percentage=100)
     ticket2.add_acks('content', 'docs', 'archive')
     Expediture.objects.create(ticket_id=ticket2.id, description='exp', amount=70)
     
     another_topic = Topic.objects.create(name='another_topic', ticket_expenses=True, grant=Grant.objects.create(full_name='g', short_name='g'))
     ticket3 = Ticket.objects.create(summary='three', topic=another_topic, rating_percentage=100)
     ticket3.add_acks('content', 'docs', 'archive')
     Expediture.objects.create(ticket_id=ticket3.id, description='exp', amount=50)
     
     trans = Transaction.objects.create(date=datetime.date(2011, 12, 24), amount=100, other=self.user, description='pay1')
     trans.tickets.add(ticket1, ticket2, ticket3)
     
     self.assertEqual('partially_paid', Ticket.objects.get(id=ticket1.id).payment_status)
     self.assertEqual('partially_paid', Ticket.objects.get(id=ticket2.id).payment_status)
     self.assertEqual('partially_paid', Ticket.objects.get(id=ticket3.id).payment_status)
     self.assertEqual(FinanceStatus(fuzzy=True, unpaid=60, paid=50), self.topic.payment_summary())
     self.assertEqual(FinanceStatus(fuzzy=True, unpaid=60, paid=50), another_topic.payment_summary())
     self.assertEqual({'unpaid':120, 'paid':100, 'overpaid':0}, Cluster.cluster_sums())
Example #6
0
 def test_real_cluster(self):
     ticket1 = Ticket.objects.create(summary='one', topic=self.topic, rating_percentage=100)
     ticket1.add_acks('content', 'docs', 'archive')
     tid1 = ticket1.id
     Expediture.objects.create(ticket_id=tid1, description='exp', amount=100)
     
     ticket2 = Ticket.objects.create(summary='two', topic=self.topic, rating_percentage=100)
     ticket2.add_acks('content', 'docs', 'archive')
     tid2 = ticket2.id
     Expediture.objects.create(ticket_id=tid2, description='exp', amount=200)
     
     tr1 = Transaction.objects.create(date=datetime.date(2011, 12, 24), amount=100, other=self.user, description='pay1')
     tr1.tickets.add(ticket1)
     tr1.tickets.add(ticket2)
     
     # check there is a correct cluster
     cid = min(tid1, tid2)
     self.assertEqual(cid, Ticket.objects.get(id=tid1).cluster.id)
     self.assertEqual(cid, Ticket.objects.get(id=tid2).cluster.id)
     c = Ticket.objects.get(id=tid1).cluster
     self.assertEqual(True, c.more_tickets)
     self.assertEqual(300, c.total_tickets)
     self.assertEqual(100, c.total_transactions)
     
     # check status
     self.assertEqual('partially_paid', Ticket.objects.get(id=tid1).payment_status)
     self.assertEqual('partially_paid', Ticket.objects.get(id=tid2).payment_status)
     self.assertEqual(FinanceStatus(unpaid=200, paid=100), self.topic.payment_summary())
     self.assertEqual({'unpaid':200, 'paid':100, 'overpaid':0}, Cluster.cluster_sums())
     
     # complete payment
     tr2 = Transaction.objects.create(date=datetime.date(2011, 12, 25), amount=200, other=self.user, description='pay2')
     tr2.tickets.add(ticket2)
     
     # check cluster
     self.assertEqual(cid, Ticket.objects.get(id=tid1).cluster.id)
     self.assertEqual(cid, Ticket.objects.get(id=tid2).cluster.id)
     self.assertEqual(cid, Transaction.objects.get(id=tr1.id).cluster.id)
     self.assertEqual(cid, Transaction.objects.get(id=tr2.id).cluster.id)
     c = Transaction.objects.get(id=tr2.id).cluster
     self.assertEqual(True, c.more_tickets)
     self.assertEqual(300, c.total_tickets)
     self.assertEqual(300, c.total_transactions)
     
     # check status
     self.assertEqual('paid', Ticket.objects.get(id=tid1).payment_status)
     self.assertEqual('paid', Ticket.objects.get(id=tid2).payment_status)
     self.assertEqual(FinanceStatus(paid=300), self.topic.payment_summary())
     self.assertEqual({'unpaid':0, 'paid':300, 'overpaid':0}, Cluster.cluster_sums())
     
     # overpay ticket1
     tr1p = Transaction.objects.create(date=datetime.date(2011, 12, 26), amount=5, other=self.user, description='pay1plus')
     tr1p.tickets.add(ticket1)
     
     self.assertEqual(cid, Transaction.objects.get(id=tr1p.id).cluster.id)
     self.assertEqual('overpaid', Ticket.objects.get(id=tid1).payment_status)
     self.assertEqual('overpaid', Ticket.objects.get(id=tid2).payment_status)
     self.assertEqual(FinanceStatus(paid=300, overpaid=5), self.topic.payment_summary())
     self.assertEqual({'unpaid':0, 'paid':300, 'overpaid':5}, Cluster.cluster_sums())
     
     # separate clusters
     tr1.tickets.remove(ticket2)
     
     self.assertEqual(tid1, Ticket.objects.get(id=tid1).cluster.id)
     self.assertEqual(tid1, Transaction.objects.get(id=tr1.id).cluster.id)
     self.assertEqual(tid1, Transaction.objects.get(id=tr1p.id).cluster.id)
     self.assertEqual(tid2, Ticket.objects.get(id=tid2).cluster.id)
     self.assertEqual(tid2, Transaction.objects.get(id=tr2.id).cluster.id)
     
     self.assertEqual(False, Ticket.objects.get(id=tid1).cluster.more_tickets)
     self.assertEqual('overpaid', Ticket.objects.get(id=tid1).payment_status)
     
     self.assertEqual(False, Ticket.objects.get(id=tid2).cluster.more_tickets)
     self.assertEqual('paid', Ticket.objects.get(id=tid2).payment_status)
     
     self.assertEqual(FinanceStatus(paid=300, overpaid=5), self.topic.payment_summary())
     self.assertEqual({'unpaid':0, 'paid':300, 'overpaid':5}, Cluster.cluster_sums())
     
     # reconnect make ticket2 overpaid again
     tr1.tickets.add(ticket2)
     self.assertEqual('overpaid', Ticket.objects.get(id=tid2).payment_status)
     self.assertEqual(FinanceStatus(paid=300, overpaid=5), self.topic.payment_summary())
     self.assertEqual({'unpaid':0, 'paid':300, 'overpaid':5}, Cluster.cluster_sums())