# -*- encoding: utf-8 -*-
from braces.views import LoginRequiredMixin, StaffuserRequiredMixin
from django.contrib import messages
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.utils import timezone
from django.views.generic import (
DetailView,
FormView,
ListView,
UpdateView,
RedirectView,
TemplateView,
)
from base.view_utils import BaseMixin
from checkout.forms import ObjectPaymentPlanInstalmentEmptyForm
from checkout.models import (
Checkout,
ObjectPaymentPlan,
ObjectPaymentPlanInstalment,
)
from checkout.views import (
CheckoutMixin,
CheckoutSuccessMixin,
CONTENT_OBJECT_PK,
)
from .forms import EmptyForm, SalesLedgerCheckoutForm, SalesLedgerEmptyForm
from .models import SalesLedger
# class ExampleObjectPaymentPlanDepositListView(ListView):
#
# model = ObjectPaymentPlan
# paginate_by = 10
# template_name = 'example/object_payment_plan_deposit_list.html'
#
# def get_queryset(self):
# return ObjectPaymentPlan.objects.outstanding_payment_plans
[docs]class ExampleObjectPaymentPlanDepositChargeUpdateView(
LoginRequiredMixin, StaffuserRequiredMixin, UpdateView
):
form_class = ObjectPaymentPlanInstalmentEmptyForm
model = ObjectPaymentPlanInstalment
template_name = "example/object_payment_plan_deposit_charge.html"
[docs] def get_success_url(self):
return reverse("checkout.object.payment.plan.instalment.audit.list")
[docs]class HomeView(ListView):
model = SalesLedger
template_name = "example/home.html"
[docs] def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
outstanding_payment_plans = (
ObjectPaymentPlan.objects.outstanding_payment_plans
)
context.update(
dict(outstanding_payment_plans=outstanding_payment_plans)
)
return context
[docs]class SalesLedgerChargeUpdateView(LoginRequiredMixin, BaseMixin, UpdateView):
model = SalesLedger
form_class = SalesLedgerEmptyForm
template_name = "example/charge.html"
[docs] def get_success_url(self):
return reverse("checkout.list.audit")
[docs]class SalesLedgerCheckoutView(CheckoutMixin, BaseMixin, UpdateView):
"""A charge can be made by the logged in user or an anonymous user."""
model = SalesLedger
form_class = SalesLedgerCheckoutForm
template_name = "example/checkout.html"
[docs]class SalesLedgerSessionRedirectView(RedirectView):
"""Set session variable so permission checks pass in checkout."""
permanent = False
[docs] def get_redirect_url(self, *args, **kwargs):
pk = kwargs["pk"]
self.request.session[CONTENT_OBJECT_PK] = pk
return reverse("example.sales.ledger.checkout", args=[pk])
[docs]class SalesLedgerCheckoutSuccessView(
CheckoutSuccessMixin, BaseMixin, DetailView
):
template_name = "example/checkout_success.html"
[docs]class SettingsView(BaseMixin, TemplateView):
template_name = "example/settings.html"