Ejemplo n.º 1
0
    def pay(self, user):
        self.payed_by = user
        self.payed_at = date.today()
        self.save()

        from expenses.models import Comment
        comment = Comment(author=user.profile,
                          invoice=self,
                          content="Betalade fakturan ```" + str(self) + "```")
        comment.save()
Ejemplo n.º 2
0
    def attest(self, user):
        self.attested_by = user.profile
        self.attest_date = date.today()

        self.save()
        from expenses.models import Comment
        comment = Comment(author=user.profile,
                          invoice=self.invoice,
                          content="Attesterar fakturadelen ```" + str(self) +
                          "```")
        comment.save()
Ejemplo n.º 3
0
def edit_expense_verification(request, pk):
    try:
        expense = Expense.objects.get(pk=pk)
    except ObjectDoesNotExist:
        raise Http404("Utlägget finns inte")

    if not request.user.profile.may_account(expense=expense):
        return HttpResponseForbidden("Du har inte rättigheter att bokföra det här")
    if expense.reimbursement is None:
        return HttpResponseBadRequest("Du kan inte bokföra det här utlägget än")

    if request.method == 'POST':
        expense.verification = request.POST['verification']
        expense.save()

        Comment(
            author=request.user.profile,
            expense=expense,
            content="Ändrade verifikationsnumret till: " + expense.verification
        ).save()

        return HttpResponseRedirect(reverse('expenses-show', kwargs={'pk': expense.id}))
    else:
        return render(request, 'expenses/edit-verification.html', {
            "expense": expense,
            "expense_parts": expense.expensepart_set.all()
        })
Ejemplo n.º 4
0
    def create(self, request, **kwargs):
        """
        Create a new comment from a JSON ID with the Expense ID and the content of the comment

        :param request:     HTTP request
        """
        # Build Comment object from JSON
        try:
            json_args = json.loads(request.POST['json'])

            c = Comment(expense_id=json_args['expense'],
                        author=request.user,
                        date=date.today(),
                        content=json_args['content'])
        except KeyError:
            return Response(status=status.HTTP_400_BAD_REQUEST)

        # Save to DB and give 201 response
        c.save()
        return Response({'comment': c.to_dict()},
                        status=status.HTTP_201_CREATED)
Ejemplo n.º 5
0
    def create(self, request, **kwargs):
        """
        Create a new comment from a JSON ID with the Expense ID and the content of the comment

        :param request:     HTTP request
        """
        # Build Comment object from JSON
        try:
            json_args = json.loads(request.POST['json'])

            c = Comment(
                expense_id=json_args['expense'],
                author=request.user,
                date=date.today(),
                content=json_args['content']
            )
        except KeyError:
            return Response(status=status.HTTP_400_BAD_REQUEST)

        # Save to DB and give 201 response
        c.save()
        return Response({'comment': c.to_dict()}, status=status.HTTP_201_CREATED)
Ejemplo n.º 6
0
def invoice_set_verification(request, invoice_pk):
    try:
        invoice = Invoice.objects.get(pk=invoice_pk)
    except ObjectDoesNotExist:
        raise Http404("Fakturan finns inte")

    if not request.user.profile.may_account(invoice=invoice):
        return HttpResponseForbidden("Du har inte rättigheter att bokföra det här")
    if invoice.payed_by is None:
        return HttpResponseBadRequest("Du kan inte bokföra den här fakturan än")

    invoice.verification = request.POST['verification']
    invoice.save()

    comment = Comment(
        author=request.user.profile,
        invoice=invoice,
        content="Bokförde med verifikationsnumret: " + invoice.verification
    )
    comment.save()

    return HttpResponseRedirect(reverse('admin-account'))
Ejemplo n.º 7
0
def set_verification(request, expense_pk):
    try:
        expense = Expense.objects.get(pk=expense_pk)
    except ObjectDoesNotExist:
        raise Http404("Utlägget finns inte")

    if not request.user.profile.may_account(expense=expense):
        return HttpResponseForbidden("Du har inte rättigheter att bokföra det här")
    if expense.reimbursement is None:
        return HttpResponseBadRequest("Du kan inte bokföra det här utlägget än")

    expense.verification = request.POST['verification']
    expense.save()

    comment = Comment(
        author=request.user.profile,
        expense=expense,
        content="Bokförde med verifikationsnumret: " + expense.verification
    )
    comment.save()

    return HttpResponseRedirect(reverse('admin-account'))
Ejemplo n.º 8
0
def invoice_set_verification(request, invoice_pk):
    try:
        invoice = Invoice.objects.get(pk=invoice_pk)
    except ObjectDoesNotExist:
        raise Http404("Fakturan finns inte")

    if not request.user.profile.may_account(invoice=invoice):
        return HttpResponseForbidden("Du har inte rättigheter att bokföra det här")
    if invoice.payed_by is None:
        return HttpResponseBadRequest("Du kan inte bokföra den här fakturan än")

    invoice.verification = request.POST['verification']
    invoice.save()

    comment = Comment(
        author=request.user.profile,
        invoice=invoice,
        content="Bokförde med verifikationsnumret: " + invoice.verification
    )
    comment.save()

    return HttpResponseRedirect(reverse('admin-account'))
Ejemplo n.º 9
0
def set_verification(request, expense_pk):
    try:
        expense = Expense.objects.get(pk=expense_pk)
    except ObjectDoesNotExist:
        raise Http404("Utlägget finns inte")

    if not request.user.profile.may_account(expense=expense):
        return HttpResponseForbidden("Du har inte rättigheter att bokföra det här")
    if expense.reimbursement is None:
        return HttpResponseBadRequest("Du kan inte bokföra det här utlägget än")

    expense.verification = request.POST['verification']
    expense.save()

    comment = Comment(
        author=request.user.profile,
        expense=expense,
        content="Bokförde med verifikationsnumret: " + expense.verification
    )
    comment.save()

    return HttpResponseRedirect(reverse('admin-account'))
Ejemplo n.º 10
0
def confirm_expense(request, pk):
    if request.method == 'POST':
        try:
            expense = Expense.objects.get(pk=pk)

            if not dauth.has_permission('confirm', request):
                return HttpResponseForbidden("Du har inte rättigheterna för att se den här sidan")

            expense.confirmed_by = request.user
            expense.confirmed_at = date.today()
            expense.save()

            comment = Comment(
                expense=expense,
                author=request.user.profile,
                content='Jag bekräftar att kvittot finns i pärmen.'
            )
            comment.save()

            return HttpResponseRedirect(reverse('admin-confirm'))
        except ObjectDoesNotExist:
            raise Http404("Utlägget finns inte")
    else:
        raise Http404()
Ejemplo n.º 11
0
def confirm_expense(request, pk):
    if request.method == 'POST':
        try:
            expense = Expense.objects.get(pk=pk)

            if not dauth.has_permission('confirm', request):
                return HttpResponseForbidden("Du har inte rättigheterna för att se den här sidan")

            expense.confirmed_by = request.user
            expense.confirmed_at = date.today()
            expense.save()

            comment = Comment(
                expense=expense,
                author=request.user.profile,
                content='Jag bekräftar att kvittot finns i pärmen.'
            )
            comment.save()

            return HttpResponseRedirect(reverse('admin-confirm'))
        except ObjectDoesNotExist:
            raise Http404("Utlägget finns inte")
    else:
        raise Http404()