def internaltransfer_pdf(request, pk): from accounting_tools.models import InternalTransfer transfers = [get_object_or_404(InternalTransfer, pk=pk_, deleted=False) for pk_ in filter(lambda x: x, pk.split(','))] transfers = [tr for tr in transfers if tr.rights_can('SHOW', request.user)] if not transfers: raise Http404 elif len(transfers) == 1: return generate_pdf("accounting_tools/internaltransfer/single_pdf.html", request, {'object': transfers[0]}) else: return generate_pdf("accounting_tools/internaltransfer/multiple_pdf.html", request, {'objects': transfers})
def internaltransfer_pdf(request, pk): from accounting_tools.models import InternalTransfer transfers = [get_object_or_404(InternalTransfer, pk=pk_, deleted=False) for pk_ in filter(lambda x: x, pk.split(','))] transfers = filter(lambda tr: tr.rights_can('SHOW', request.user), transfers) if not transfers: raise Http404 elif len(transfers) == 1: return generate_pdf("accounting_tools/internaltransfer/single_pdf.html", request, {'object': transfers[0]}) else: return generate_pdf("accounting_tools/internaltransfer/multiple_pdf.html", request, {'objects': transfers})
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 budget_pdf(request, pk): from accounting_main.models import Budget budget = get_object_or_404(Budget, pk=pk, deleted=False) if not budget.rights_can('SHOW', request.user): raise Http404 lines = map( lambda line: { 'table_id': 'incomes' if line.amount > 0 else 'outcomes', 'account': line.account, 'description': line.description, 'amount': abs(float(line.amount)) }, list(budget.budgetline_set.all())) accounts = sorted(list(set(map(lambda line: line['account'], lines))), key=lambda acc: acc.account_number) retour = [[[ line for line in lines if line['account'] == acc and line['table_id'] == tab ] for acc in accounts] for tab in ['incomes', 'outcomes']] retour = [[{ 'account': block[0]['account'], 'total': sum(map(lambda elem: elem['amount'], block)), 'entries': block } if block else {} for block in kind] for kind in retour] return generate_pdf("accounting_main/budget/pdf.html", request, { 'object': budget, 'incomes': retour[0], 'outcomes': retour[1] })
def expenseclaim_pdf(request, pk): from accounting_tools.models import ExpenseClaim expenseclaim = get_object_or_404(ExpenseClaim, pk=pk, deleted=False) if not expenseclaim.rights_can('SHOW', request.user): raise Http404 return generate_pdf("accounting_tools/expenseclaim/pdf.html", request, {'object': expenseclaim}, [f.file for f in expenseclaim.get_pdf_files()])
def provider_invoice_pdf(request, pk): from accounting_tools.models import ProviderInvoice invoice = get_object_or_404(ProviderInvoice, pk=pk, deleted=False) if not invoice.rights_can('SHOW', request.user): raise Http404 return generate_pdf("accounting_tools/providerinvoice/pdf.html", request, {'object': invoice}, [f.file for f in invoice.get_pdf_files()])
def cashbook_pdf(request, pk): from accounting_tools.models import CashBook cashbook = get_object_or_404(CashBook, pk=pk, deleted=False) if not cashbook.rights_can('SHOW', request.user): raise Http404 return generate_pdf("accounting_tools/cashbook/pdf.html", request, {'object': cashbook}, [f.file for f in cashbook.get_pdf_files()])
def withdrawal_pdf(request, pk): from accounting_tools.models import Withdrawal withdrawal = get_object_or_404(Withdrawal, pk=pk, deleted=False) if not withdrawal.rights_can('SHOW', request.user): raise Http404 return generate_pdf("accounting_tools/withdrawal/pdf.html", request, {'object': withdrawal})
def booking_pdf(request, pk): from vehicles.models import Booking booking = get_object_or_404(Booking, pk=pk, deleted=False) if not booking.rights_can('SHOW', request.user): raise Http404 return generate_pdf("vehicles/booking/pdf.html", request, {'object': booking})
def loanagreement_pdf(request, pk): from logistics.models import SupplyReservation reservation = get_object_or_404(SupplyReservation, pk=pk, deleted=False) if not reservation.rights_can('SHOW', request.user): raise Http404 return generate_pdf("logistics/supplyreservation/pdf.html", request, {'supplyreservation': reservation})
def invoice_pdf(request, pk): from accounting_tools.models import Invoice invoice = get_object_or_404(Invoice, pk=pk, deleted=False) if not invoice.rights_can('DOWNLOAD_PDF', request.user): raise Http404 img = invoice.generate_bvr() img = img.resize((1414, 1000), Image.LANCZOS) img.save(os.path.join(settings.MEDIA_ROOT, 'cache/bvr/{}.png').format(invoice.pk)) return generate_pdf("accounting_tools/invoice/pdf.html", request, {'invoice': invoice})
def pdf_list_cost_centers(request, pk): from accounting_core.models import AccountingYear, CostCenter try: ay = AccountingYear.objects.get(pk=pk) except AccountingYear.DoesNotExist: raise Http404 if not ay.rights_can('SHOW', request.user): raise Http404 cc = CostCenter.objects.filter(accounting_year=ay, deleted=False).order_by('account_number') return generate_pdf("accounting_core/costcenter/liste_pdf.html", request, {'cost_centers': cc, 'ay': ay})
def pdf_list_accounts(request, pk): from accounting_core.models import AccountingYear, AccountCategory try: ay = AccountingYear.objects.get(pk=pk) except AccountingYear.DoesNotExist: raise Http404 if not ay.rights_can('SHOW', request.user): raise Http404 root_ac = AccountCategory.objects.filter(accounting_year=ay, parent_hierarchique=None).order_by('order') return generate_pdf("accounting_core/account/liste_pdf.html", request, {'root_ac': root_ac, 'ay': ay})
def invoice_pdf(request, pk): from accounting_tools.models import Invoice invoice = get_object_or_404(Invoice, pk=pk, deleted=False) if not invoice.rights_can('SHOW', request.user): raise Http404 img = invoice.generate_bvr() img = img.resize((1414, 1000), Image.LANCZOS) img.save(os.path.join(settings.MEDIA_ROOT, 'cache/bvr/{}.png').format(invoice.pk)) return generate_pdf("accounting_tools/invoice/pdf.html", request, {'invoice': invoice})
def budget_pdf(request, pk): from accounting_main.models import Budget budget = get_object_or_404(Budget, pk=pk, deleted=False) if not budget.rights_can('SHOW', request.user): raise Http404 lines = map(lambda line: {'table_id': 'incomes' if line.amount > 0 else 'outcomes', 'account': line.account, 'description': line.description, 'amount': abs(float(line.amount))}, list(budget.budgetline_set.all())) accounts = sorted(list(set(map(lambda line: line['account'], lines))), key=lambda acc: acc.account_number) retour = [[[line for line in lines if line['account'] == acc and line['table_id'] == tab] for acc in accounts] for tab in ['incomes', 'outcomes']] retour = map(lambda kind: map(lambda block: {'account': block[0]['account'], 'total': sum(map(lambda elem: elem['amount'], block)), 'entries': block} if block else {}, kind), retour) return generate_pdf("accounting_main/budget/pdf.html", request, {'object': budget, 'incomes': retour[0], 'outcomes': retour[1]})
def users_myunit_pdf(request): """PDF of users in the current unit""" current_unit = get_current_unit(request) if not current_unit.is_user_in_groupe(request.user): raise Http404 no_display = bool(request.GET.get('no_display', False)) liste = [] for accred in current_unit.current_accreds(): accred.truffe2_tmp_pdf_display_mobile = UserPrivacy.user_can_access(request.user, accred.user, 'mobile') liste.append(accred) return generate_pdf("users/users/myunit_pdf.html", request, {'unit': current_unit, 'liste': liste, 'no_display_name': no_display})
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})