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()
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()
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() })
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)
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)
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'))
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'))
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()