Source code for example_checkout.models

# -*- encoding: utf-8 -*-
from django.conf import settings
from django.db import models
from django.urls import reverse

from checkout.models import CheckoutAction
from stock.models import Product


[docs]class SalesLedgerManager(models.Manager):
[docs] def create_sales_ledger(self, contact, product, quantity): obj = self.model(contact=contact, product=product, quantity=quantity) obj.save() return obj
[docs]class SalesLedger(models.Model): """List of prices.""" contact = models.ForeignKey( settings.CONTACT_MODEL, on_delete=models.CASCADE ) product = models.ForeignKey(Product, on_delete=models.CASCADE) quantity = models.IntegerField() objects = SalesLedgerManager() class Meta: ordering = ("pk",) verbose_name = "Sales ledger" verbose_name_plural = "Sales ledger" def __str__(self): return "{}".format(self.checkout_description)
[docs] def get_absolute_url(self): """just for testing.""" return reverse("project.home")
@property def checkout_actions(self): return [ CheckoutAction.CARD_REFRESH, CheckoutAction.INVOICE, CheckoutAction.PAYMENT, CheckoutAction.PAYMENT_PLAN, ] @property def checkout_can_charge(self): """We can always take a payment for this object!""" return True @property def checkout_name(self): return "{}".format(self.contact.user.get_full_name()) @property def checkout_description(self): result = "{} x {} @ {}".format( self.product.name, self.quantity, self.product.price ) return [result] @property def checkout_email(self): return self.contact.user.email
[docs] def checkout_fail(self, checkout): """Update the object to record the payment failure. Called from within a transaction so you can update the model. """ pass
[docs] def checkout_fail_url(self, checkout_pk): """just for testing.""" return reverse("checkout.list.audit")
[docs] def checkout_success(self, checkout): """Update the object to record the payment success. Called from within a transaction so you can update the model. """ pass
[docs] def checkout_success_url(self, checkout_pk): """just for testing.""" return reverse( "example.sales.ledger.checkout.success", args=[checkout_pk] )
@property def checkout_total(self): return self.product.price * self.quantity
[docs] def instalment_fail(self, checkout, due): pass
[docs] def instalment_success(self, checkout): pass