Coverage for /home/tribaal/workspace/django-shop/shop/models/ordermodel: 91.07%

# Coverage for /home/tribaal/workspace/django-shop/shop/models/ordermodel : 91.07%

## 52 statements 48 run 4 missing 0 excluded 1 partial

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | # -*- coding: utf-8 -*- from distutils.version import LooseVersion from django.conf import settings from django.db import models from django.db.models.signals import pre_delete from django.utils.translation import ugettext_lazy as _ from shop.models.productmodel import Product from shop.util.fields import CurrencyField from shop.util.loader import load_class import django #============================================================================== # Extensibility #============================================================================== # This overrides the various models with classes loaded from the corresponding # setting if it exists. # Order model ORDER_MODEL = getattr(settings, 'SHOP_ORDER_MODEL', 'shop.models.defaults.order.Order') Order = load_class(ORDER_MODEL, 'SHOP_ORDER_MODEL') # Order item model ORDERITEM_MODEL = getattr(settings, 'SHOP_ORDERITEM_MODEL', 'shop.models.defaults.orderitem.OrderItem') OrderItem = load_class(ORDERITEM_MODEL, 'SHOP_ORDERITEM_MODEL') # Now we clear refrence to product from every OrderItem def clear_products(sender, instance, using, **kwargs): for oi in OrderItem.objects.filter(product=instance): oi.product = None oi.save() 37if LooseVersion(django.get_version()) < LooseVersion('1.3'): pre_delete.connect(clear_products, sender=Product) class OrderExtraInfo(models.Model): """ A holder for extra textual information to attach to this order. """ order = models.ForeignKey(Order, related_name="extra_info", verbose_name=_('Order')) text = models.TextField(verbose_name=_('Extra info')) class Meta(object): app_label = 'shop' verbose_name = _('Order extra info') verbose_name_plural = _('Order extra info') class ExtraOrderPriceField(models.Model): """ This will make Cart-provided extra price fields persistent since we want to "snapshot" their statuses at the time when the order was made """ order = models.ForeignKey(Order, verbose_name=_('Order')) label = models.CharField(max_length=255, verbose_name=_('Label')) value = CurrencyField(verbose_name=_('Amount')) # Does this represent shipping costs? is_shipping = models.BooleanField(default=False, editable=False, verbose_name=_('Is shipping')) class Meta(object): app_label = 'shop' verbose_name = _('Extra order price field') verbose_name_plural = _('Extra order price fields') class ExtraOrderItemPriceField(models.Model): """ This will make Cart-provided extra price fields persistent since we want to "snapshot" their statuses at the time when the order was made """ order_item = models.ForeignKey(OrderItem, verbose_name=_('Order item')) label = models.CharField(max_length=255, verbose_name=_('Label')) value = CurrencyField(verbose_name=_('Amount')) class Meta(object): app_label = 'shop' verbose_name = _('Extra order item price field') verbose_name_plural = _('Extra order item price fields') class OrderPayment(models.Model): """ A class to hold basic payment information. Backends should define their own more complex payment types should they need to store more informtion """ order = models.ForeignKey(Order, verbose_name=_('Order')) # How much was payed with this particular transfer amount = CurrencyField(verbose_name=_('Amount')) transaction_id = models.CharField(max_length=255, verbose_name=_('Transaction ID'), help_text=_("The transaction processor's reference")) payment_method = models.CharField(max_length=255, verbose_name=_('Payment method'), help_text=_("The payment backend use to process the purchase")) class Meta(object): app_label = 'shop' verbose_name = _('Order payment') verbose_name_plural = _('Order payments')