Exemple #1
0
def accounting_import_step0(request):
    """Phase 0 de l'import: Crée une nouvelle session d'import"""

    from accounting_main.models import AccountingLine

    if not AccountingLine.static_rights_can('IMPORT', request.user):
        raise Http404

    key = str(uuid.uuid4())
    session_key = 'T2_ACCOUNTING_IMPORT_{}'.format(key)

    request.session[session_key] = {'is_valid': True, 'has_data': False}

    return redirect('accounting_main-views-accounting_import_step1', key)
Exemple #2
0
def accounting_import_step0(request):
    """Phase 0 de l'import: Crée une nouvelle session d'import"""

    from accounting_main.models import AccountingLine

    if not AccountingLine.static_rights_can('IMPORT', request.user):
        raise Http404

    key = str(uuid.uuid4())
    session_key = 'T2_ACCOUNTING_IMPORT_{}'.format(key)

    request.session[session_key] = {'is_valid': True, 'has_data': False}

    return redirect('accounting_main.views.accounting_import_step1', key)
Exemple #3
0
def _get_import_session_data(request, key):

    from accounting_main.models import AccountingLine

    if not AccountingLine.static_rights_can('IMPORT', request.user):
        raise Http404

    session_key = 'T2_ACCOUNTING_IMPORT_{}'.format(key)

    session_data = request.session.get(session_key)

    if not session_data or not session_data['is_valid']:
        messages.warning(request, _(u'Session d\'importation invalide.'))
        return (None, redirect('accounting_main-views-accounting_import_step0'))

    return (session_key, session_data)
Exemple #4
0
def _get_import_session_data(request, key):

    from accounting_main.models import AccountingLine

    if not AccountingLine.static_rights_can('IMPORT', request.user):
        raise Http404

    session_key = 'T2_ACCOUNTING_IMPORT_{}'.format(key)

    session_data = request.session.get(session_key)

    if not session_data or not session_data['is_valid']:
        messages.warning(request, _(u'Session d\'importation invalide.'))
        return (None, redirect('accounting_main.views.accounting_import_step0'))

    return (session_key, session_data)
Exemple #5
0
def accounting_graph(request):

    from accounting_core.models import CostCenter
    from accounting_main.models import AccountingLine

    costcenter = get_object_or_404(CostCenter, pk=request.GET.get('costcenter'))

    if not AccountingLine.static_rights_can('LIST', request.user, costcenter.unit, costcenter.accounting_year):
        raise Http404

    data = collections.OrderedDict()

    for line in AccountingLine.objects.filter(costcenter=costcenter).order_by('date'):
        timestamp = int((time.mktime(line.date.timetuple()) + 3600) * 1000)
        data[timestamp] = -line.current_sum

    return render(request, 'accounting_main/accountingline/graph.html', {'costcenter': costcenter, 'random': str(uuid.uuid4()), 'data': data})
Exemple #6
0
def accounting_graph(request):

    from accounting_core.models import CostCenter
    from accounting_main.models import AccountingLine

    costcenter = get_object_or_404(CostCenter, pk=request.GET.get('costcenter'))

    if not AccountingLine.static_rights_can('LIST', request.user, costcenter.unit, costcenter.accounting_year):
        raise Http404

    data = collections.OrderedDict()

    for line in AccountingLine.objects.filter(costcenter=costcenter).order_by('date'):
        timestamp = int((time.mktime(line.date.timetuple()) + 3600) * 1000)
        data[timestamp] = -line.current_sum

    return render(request, 'accounting_main/accountingline/graph.html', {'costcenter': costcenter, 'random': str(uuid.uuid4()), 'data': data})
Exemple #7
0
def accounting_budget_view(request):

    from accounting_core.models import CostCenter, AccountCategory
    from accounting_main.models import AccountingLine

    costcenter = get_object_or_404(CostCenter, pk=request.GET.get('costcenter'))

    if not AccountingLine.static_rights_can('LIST', request.user, costcenter.unit, costcenter.accounting_year):
        raise Http404

    root_acs = AccountCategory.objects.filter(deleted=False, accounting_year=costcenter.accounting_year, parent_hierarchique=None).order_by('order')

    def _build_recu_list(base_list):

        retour = []

        for elem in base_list:

            if elem.get_children_categories():
                retour.append((elem, _build_recu_list(elem.get_children_categories()), None))
            else:
                accouts_with_total = []
                for account in elem.get_accounts():
                    data = costcenter.accountingline_set.filter(deleted=False, account=account).aggregate(pos=Sum('input'), neg=Sum('output'))
                    if not data['pos']:
                        data['pos'] = 0
                    if not data['neg']:
                        data['neg'] = 0
                    data['total'] = data['pos'] - data['neg']
                    accouts_with_total.append((account, data))

                retour.append((elem, None, accouts_with_total))

        return retour

    data = _build_recu_list(root_acs)

    return render(request, 'accounting_main/accountingline/budget_view.html', {'costcenter': costcenter, 'random': str(uuid.uuid4()), 'data': data})
Exemple #8
0
def accounting_budget_view(request):

    from accounting_core.models import CostCenter, AccountCategory
    from accounting_main.models import AccountingLine
    from .forms2 import BudgetFilterForm

    costcenter = get_object_or_404(CostCenter,
                                   pk=request.GET.get('costcenter'))

    start_date, end_date = None, None

    if request.method == 'POST':
        form = BudgetFilterForm(request.POST)

        if form.is_valid():
            start_date, end_date = form.cleaned_data[
                'start'], form.cleaned_data['end']

    else:
        form = BudgetFilterForm()

        form.fields[
            'start'].initial = costcenter.accounting_year.start_date.date()
        form.fields['end'].initial = costcenter.accounting_year.end_date.date()

    if not AccountingLine.static_rights_can(
            'LIST', request.user, costcenter.unit, costcenter.accounting_year):
        raise Http404

    root_acs = AccountCategory.objects.filter(
        deleted=False,
        accounting_year=costcenter.accounting_year,
        parent_hierarchique=None).order_by('order')

    def _build_recu_list(base_list):

        retour = []

        for elem in base_list:

            if elem.get_children_categories():
                retour.append(
                    (elem, _build_recu_list(elem.get_children_categories()),
                     None))
            else:
                accouts_with_total = []
                elem.show_total = False
                elem.total = 0
                for account in elem.get_accounts():
                    data = costcenter.accountingline_set.filter(
                        deleted=False, account=account)

                    if start_date or end_date:
                        data = data.filter(date__gte=start_date,
                                           date__lte=end_date)

                    data = data.aggregate(pos=Sum('input'), neg=Sum('output'))
                    if not data['pos']:
                        data['pos'] = 0
                    if not data['neg']:
                        data['neg'] = 0

                    data['total'] = data['pos'] - data['neg']

                    elem.total += data['total']

                    if data['pos'] or data['neg']:
                        elem.show_total = True

                    accouts_with_total.append((account, data))

                retour.append((elem, None, accouts_with_total))

        return retour

    data = _build_recu_list(root_acs)

    return render(
        request, 'accounting_main/accountingline/budget_view.html', {
            'costcenter': costcenter,
            'random': str(uuid.uuid4()),
            'data': data,
            'form': form,
            'start': start_date,
            'end': end_date
        })
Exemple #9
0
def accounting_budget_view(request):

    from accounting_core.models import CostCenter, AccountCategory
    from accounting_main.models import AccountingLine
    from .forms2 import BudgetFilterForm

    costcenter = get_object_or_404(CostCenter, pk=request.GET.get('costcenter'))

    start_date, end_date = None, None

    if request.method == 'POST':
        form = BudgetFilterForm(request.POST)

        if form.is_valid():
            start_date, end_date = form.cleaned_data['start'], form.cleaned_data['end']

    else:
        form = BudgetFilterForm()

        form.fields['start'].initial = costcenter.accounting_year.start_date.date()
        form.fields['end'].initial = costcenter.accounting_year.end_date.date()

    if not AccountingLine.static_rights_can('LIST', request.user, costcenter.unit, costcenter.accounting_year):
        raise Http404

    root_acs = AccountCategory.objects.filter(deleted=False, accounting_year=costcenter.accounting_year, parent_hierarchique=None).order_by('order')

    def _build_recu_list(base_list):

        retour = []

        for elem in base_list:

            if elem.get_children_categories():
                retour.append((elem, _build_recu_list(elem.get_children_categories()), None))
            else:
                accouts_with_total = []
                elem.show_total = False
                elem.total = 0
                for account in elem.get_accounts():
                    data = costcenter.accountingline_set.filter(deleted=False, account=account)

                    if start_date or end_date:
                        data = data.filter(date__gte=start_date, date__lte=end_date)

                    data = data.aggregate(pos=Sum('input'), neg=Sum('output'))
                    if not data['pos']:
                        data['pos'] = 0
                    if not data['neg']:
                        data['neg'] = 0

                    data['total'] = data['pos'] - data['neg']

                    elem.total += data['total']

                    if data['pos'] or data['neg']:
                        elem.show_total = True

                    accouts_with_total.append((account, data))

                retour.append((elem, None, accouts_with_total))

        return retour

    data = _build_recu_list(root_acs)

    return render(request, 'accounting_main/accountingline/budget_view.html', {'costcenter': costcenter, 'random': str(uuid.uuid4()), 'data': data, 'form': form, 'start': start_date, 'end': end_date})