Esempio n. 1
0
def operation_list(request, building_id, account_id, month=None):
    building = ApartmentGroup.objects.get(pk=building_id)
    building_accessible(request, building)
    if month == None:
        today = date.today()
        month = date(day=building.close_day, month=today.month,
                     year=today.year)
    else:
        month = datetime.strptime(month + '-%02d' % building.close_day,
                                  "%Y-%m-%d").date()
    
    l = License.for_building(building)
    l.validate_month(building, month)
    month_end = month + relativedelta(months=1) 
    
    account = Account.objects.get(pk=account_id)
    
    ops = account.operation_list(month, month_end)
    initial_penalties, final_penalties = None, None
    src_exclude = None
    
    apartment = entity_for_account(Apartment, account)
    # TODO(Stefan) there's logic put in the view, this is uncool
    if apartment != None:
        initial_penalties = apartment.penalties(month)
        final_penalties = apartment.penalties(month_end)
        src_exclude = Q(dest=apartment.building().penalties_account)
        
    service = entity_for_account(CollectingFund, account)
    if service != None:
        src_exclude = Q(doc__type='collection')
        
    initial = account.balance(month, src_exclude)
    final = account.balance(month_end, src_exclude)
    
    data = {'account': account, 'docs': ops, 'building': building,
            'initial_balance': initial, 'initial_penalties': initial_penalties,
            'final_balance': final, 'final_penalties': final_penalties,
            'month': month, 'month_end': month_end, 'service': service,
            'building': building_for_account(account)}
    return render(request, 'operation_list.html', data)
Esempio n. 2
0
 def for_fund(cls, fund):
     account = Account.objects.get(fund.pk)
     building = building_for_account(account)
     return License.for_building(building)