Changeset 162f527 for remit/finance_core/reporting.py
- Timestamp:
- Mar 27, 2010, 3:48:00 AM (15 years ago)
- Branches:
- master, client
- Children:
- eae6ea8
- Parents:
- 83d9608
- git-author:
- Alex Dehnert <adehnert@…> (03/27/10 03:48:00)
- git-committer:
- Alex Dehnert <adehnert@…> (03/27/10 03:48:00)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
remit/finance_core/reporting.py
r13e7c01 r162f527 1 1 from decimal import Decimal 2 from django.db.models import Sum 2 from django.db.models import Q, Sum 3 import finance_core.models 3 4 4 5 def build_table_annotate(line_items, main_lineitem_limit_primary, primary_axis, primary_axis_objs, secondary_axis, ): … … 7 8 table = [] 8 9 zero = Decimal('0.00') 9 for num, (pk, label, qobj, ) in enumerate(primary_axis):10 for num, (pk, label, qobj, objrel_qobj) in enumerate(primary_axis): 10 11 arcprimary[pk] = num 11 12 table.append([zero]*len(secondary_axis)) … … 17 18 # Do the real work 18 19 print secondary_axis 19 for num, ( label, qobj_lineitem, qobj_primary) in enumerate(secondary_axis):20 for num, (pk, label, qobj_lineitem, qobj_primary) in enumerate(secondary_axis): 20 21 print num 21 22 secondary_results = (primary_axis_objs.filter(main_lineitem_limit_primary, qobj_primary, ).annotate(Sum('lineitem__amount'))) … … 37 38 table = [ # Primary axis 38 39 [ # Secondary axis 39 total_amount(line_items.filter(primary[2], secondary[ 1]))40 total_amount(line_items.filter(primary[2], secondary[2])) 40 41 for secondary in secondary_axis] 41 42 for primary in primary_axis] 42 43 43 44 return table 44 45 45 46 46 build_table = build_table_annotate 47 48 49 def get_primary_axis(slug, base_area): 50 if slug == 'budget-areas': 51 return get_budget_areas(base_area) 52 else: 53 raise UnsupportedOperationException() 54 55 def get_secondary_axis(slug, base_area): 56 if slug == 'budget-areas': 57 return get_budget_areas(base_area) 58 elif slug == 'layers': 59 return get_layers(base_area) 60 else: 61 raise NotImplementedError 62 63 def get_budget_areas(base_area): 64 name = 'Budget Areas' 65 base_area_depth = base_area.depth 66 axis = [ 67 ( 68 area.pk, 69 area.indented_name(base_area_depth), 70 Q(budget_area=area), 71 Q(lineitem__budget_area=area), 72 ) 73 for area in base_area.get_descendants() 74 ] 75 axis_objs = base_area.get_descendants() 76 return name, axis, axis_objs, 77 78 def get_layers(base_area): 79 name = 'Layers' 80 axis = [ 81 ( 82 finance_core.models.layer_num(layer), 83 finance_core.models.layer_name(layer), 84 Q(layer=finance_core.models.layer_num(layer)), 85 Q(lineitem__layer=finance_core.models.layer_num(layer)), 86 ) 87 for layer in finance_core.models.layers 88 ] 89 return name, axis, None, 90
Note: See TracChangeset
for help on using the changeset viewer.