Exemple #1
0
 def render_requested_start(self, value, record):
     return fyq(value)
Exemple #2
0
 def render_approved_for(self, value, record):
     return fyq(value)
Exemple #3
0
def homologation_item_list(request, list_filter='', qtr='', yr=''):

    today = date.today()
    title='Homologation Items'
    
    prev_quarter = None
    next_quarter = None

    #
    # Figure out what subset of the data to display.
    # Choices are all, current quarter, next quarter, 
    # previous quarter, or a quarter by name
    #

    if list_filter!='':
        if list_filter=='Q':
            title = "Q%sFY%s" % (qtr,yr)
            start_date = find_quarter_start_fyq(qtr,yr)
            end_date = find_quarter_start(start_date,1)
        elif list_filter=='last_quarter':
            title = 'Last Quarter'
            start_date = find_quarter_start(today,-1)
            end_date = find_quarter_start(today,0)
        elif list_filter=='this_quarter':
            title = 'Current Quarter'
            start_date = find_quarter_start(today)
            end_date = find_quarter_start(today,1)
        elif list_filter=='next_quarter':
            title = 'Next Quarter'
            start_date = find_quarter_start(today,1)
            end_date = find_quarter_start(today,2)
            
        if start_date >= datetime(year=2011, month=10, day=1): #jjb fixme... get rid of magic number
            prev_quarter = fyq(find_quarter_start(start_date,-1))

        next_quarter = fyq(end_date)
			
        data_set = HomologationStatus.objects.filter(
            active_record=True,
            requested_date__gte=str(start_date.date()),
            requested_date__lt=str(end_date.date()))
    else:
        #
        # If the user doesn't specify a filter, display all of the items >= 2011-10-01
        #
        
		data_set = HomologationStatus.objects.filter(
            active_record=True,
            requested_date__gte='2011-10-01')

    table = HomologationTable(data_set)

    #
    # Grab the totals
    #

    approval_totals = data_set.values('approval_status'). \
        annotate(approved_sum=Sum('approved_amount')). \
        order_by('-approved_sum')

    status_totals = data_set.values('certification_status'). \
        exclude(approval_status='cancelled'). \
        annotate(approved_sum=Sum('approved_amount')). \
        order_by('-approved_sum')

    type_totals = data_set.values('homologation_item__cert_type'). \
        exclude(approval_status='cancelled'). \
        annotate(approved_sum=Sum('approved_amount')). \
        order_by('-approved_sum')

    #
    # Display table using Django Tables2
    #

    RequestConfig(request).configure(table)

    return render(request, "budget/item_list.html", 
        { 'table': table,
          'title': title,
          'approval_totals': approval_totals,
          'status_totals': status_totals,
          'type_totals': type_totals,
          'prev_quarter': prev_quarter,
          'next_quarter': next_quarter})