def export_all_demands(request): from accounting_core.models import AccountingYear from accounting_tools.models import Subvention if not Subvention.static_rights_can('EXPORT', request.user): raise Http404 years = AccountingYear.objects.filter(deleted=False).order_by('start_date') subventions = [] for ay in years: subv = Subvention.objects.filter(accounting_year=ay, deleted=False).order_by('unit__name', 'unit_blank_name') if subv: subv = list(subv) + [get_statistics(subv)] subventions.append((ay.name, subv)) summary = [] units = sorted(list(set(map(lambda subv: subv.get_real_unit_name(), list(Subvention.objects.all()))))) for unit_name in units: line = [unit_name] for year in years: year_subv = Subvention.objects.filter(accounting_year=year, deleted=False).filter(Q(unit__name=unit_name) | Q(unit_blank_name=unit_name)).first() if year_subv: line += [year_subv.amount_asked, year_subv.amount_given, year_subv.mobility_asked, year_subv.mobility_asked] else: line += ["", "", "", ""] summary.append(line) return generate_pdf("accounting_tools/subvention/subventions_pdf.html", request, {'subventions': subventions, 'summary': summary, 'years': years})
def export_demands_yearly(request, ypk): from accounting_core.models import AccountingYear from accounting_tools.models import Subvention if not Subvention.static_rights_can('EXPORT', request.user): raise Http404 try: ay = AccountingYear.objects.get(pk=ypk) subventions = Subvention.objects.filter(accounting_year=ay, deleted=False).order_by('unit__name', 'unit_blank_name') if subventions: subventions = list(subventions) + [get_statistics(subventions)] subv = [(ay.name, subventions)] except AccountingYear.DoesNotExist: subv = [(_(u'Période inconnue'), Subvention.objects.none())] return generate_pdf("accounting_tools/subvention/subventions_pdf.html", request, {'subventions': subv})
def test_subvention_deleted(self): from accounting_tools.models import Subvention Subvention(id=2, name='bad subvention', amount_asked=456, kind='subvention', linked_budget_id=1, accounting_year_id=1, unit_id=1, deleted=True).save() self.call_check_html('/accounting/tools/subvention/deleted', data={'upk':1}) self.call_check_redirect('/accounting/tools/subvention/deleted', method='post', data={'upk':1, 'pk':2}, redirect_url='/accounting/tools/subvention/')
def setup_testing_accounting_tools(user): from accounting_tools.models import Withdrawal, InternalTransfer, FinancialProvider, Subvention, SubventionFile from accounting_tools.models import ProviderInvoice, Invoice, CashBook, CashBookLine, ExpenseClaim, ExpenseClaimLine, ExpenseClaimLogging now = timezone.now() Withdrawal(id=1, name='reason', user=user, amount=12.34, desired_date=now, withdrawn_date=None, accounting_year_id=1, costcenter_id=1).save() InternalTransfer(id=1, name='reason', account_id=4, cost_center_from_id=1, cost_center_to_id=1, amount=98.76, transfert_date=now, accounting_year_id=1, status='3_archive').save() FinancialProvider( id=1, name='Financial name', tva_number='123456', iban_ou_ccp='ABCDEFG', bic='XYZ', address='Rue Des Arc en Ciel 25 - Case Postale 2, CH-1015 Lausanne' ).save() Subvention(id=1, name='Subvention', amount_asked=456, kind='subvention', linked_budget_id=1, accounting_year_id=1, unit_id=1).save() ProviderInvoice(id=1, name='Provider invoice', user=user, currency='EUR', provider_id=1, accounting_year_id=1, costcenter_id=1).save() Invoice(id=1, title='invoice', accounting_year_id=1, costcenter_id=1).save() CashBook(id=1, name='cash', user=user, nb_proofs=1, accounting_year_id=1, costcenter_id=1, status='6_archived').save() CashBookLine(cashbook_id=1, date=now, helper='2_sell', label='sell', account_id=2, value=123, tva=0, value_ttc=123).save() CashBookLine(cashbook_id=1, date=now, helper='1_deposit', label='deposit', account_id=7, value=123, tva=0, value_ttc=123).save() ExpenseClaim(id=1, name='expense', user=user, nb_proofs=1, accounting_year_id=1, costcenter_id=1, status='6_archived').save() ExpenseClaimLine(expense_claim_id=1, label='claim', account_id=5, value=54.65, tva=0, value_ttc=54.65).save() ExpenseClaimLogging(object_id=1, when=now, who=user, what='created').save() media_path = join(dirname(dirname(__file__)), 'media') copyfile(join(media_path, 'img/logo_testing.png'), join(media_path, 'uploads/files/logo_testing.png')) copyfile(join(media_path, 'sound', 'bigbox.mp3'), join(media_path, 'uploads/files/bigbox.mp3')) SubventionFile(id=1, uploader_id=1, file='uploads/files/logo_testing.png').save()