Ejemplo n.º 1
0
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})
Ejemplo n.º 2
0
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})
Ejemplo n.º 3
0
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})
Ejemplo n.º 4
0
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]
    })
Ejemplo n.º 5
0
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})
Ejemplo n.º 6
0
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()])
Ejemplo n.º 7
0
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()])
Ejemplo n.º 8
0
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()])
Ejemplo n.º 9
0
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()])
Ejemplo n.º 10
0
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()])
Ejemplo n.º 11
0
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})
Ejemplo n.º 12
0
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})
Ejemplo n.º 13
0
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})
Ejemplo n.º 14
0
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})
Ejemplo n.º 15
0
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})
Ejemplo n.º 16
0
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})
Ejemplo n.º 17
0
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})
Ejemplo n.º 18
0
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})
Ejemplo n.º 19
0
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})
Ejemplo n.º 20
0
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})
Ejemplo n.º 21
0
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})
Ejemplo n.º 22
0
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]})
Ejemplo n.º 23
0
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})
Ejemplo n.º 24
0
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})
Ejemplo n.º 25
0
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})
Ejemplo n.º 26
0
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})