Source

django-lfs / lfs / shipping / models.py

Diff from to

File lfs/shipping/models.py

 from django.utils.translation import ugettext_lazy as _
 
 # lfs imports
+from lfs.criteria.base import Criteria
 from lfs.catalog.models import DeliveryTime
 from lfs.core.utils import import_symbol
-from lfs.payment.models import CriteriaObjects
 from lfs.tax.models import Tax
 
 # Load logger
         return super(ActiveShippingMethodManager, self).get_query_set().filter(active=True)
 
 
-class ShippingMethod(models.Model):
+class ShippingMethod(models.Model, Criteria):
     """
     Decides how bought products are delivered to the customer.
 
         method either has no additional prices or if none of he additional prices
         is valid.
 
-    criteria_objects
+    criteria
         A shipping method may have several criteria which decide whether the
         shipping method is valid. It is valid if all criteria are true. Only
         active and valid shipping methods are provided to the shop customer.
     tax = models.ForeignKey(Tax, verbose_name=_(u"Tax"), blank=True, null=True)
     price = models.FloatField(_(u"Price"), default=0.0)
     delivery_time = models.ForeignKey(DeliveryTime, verbose_name=_(u"Delivery time"), blank=True, null=True)
-    criteria_objects = generic.GenericRelation(CriteriaObjects, object_id_field="content_id", content_type_field="content_type")
     price_calculator = models.CharField(_(u"Price Calculator"), max_length=200, choices=settings.LFS_SHIPPING_METHOD_PRICE_CALCULATORS, default=settings.LFS_SHIPPING_METHOD_PRICE_CALCULATORS[0][0])
 
     objects = ActiveShippingMethodManager()
     def __unicode__(self):
         return self.name
 
-    def is_valid(self, request, product=None):
-        """
-        The shipping method is valid if it has no criteria or if all assigned
-        criteria are true.
-
-        If product is given the product is tested otherwise the whole cart.
-        """
-        from lfs.criteria import utils as criteria_utils
-        return criteria_utils.is_valid(self, request, product)
-
     def get_price(self, request):
         """Returns the gross price of the shipping method.
 
         else:
             return self.tax.rate
 
-class ShippingMethodPrice(models.Model):
+
+class ShippingMethodPrice(models.Model, Criteria):
     """
     An additional price for a shipping method.
 
         If set to True the shipping price is active. Otherwise it is not active
         and hence not considered with the calculation of the price. Not used at
         the moment within the GUI. Every price is active immediately.
-
-    criteria_objects
-        A shipping method price may have some criteria. Only when all criteria
-        are true the price is valid. The first valid price is the actual price
-        of the belonging shipping method.
     """
     shipping_method = models.ForeignKey(ShippingMethod, verbose_name=_(u"shipping_method"), related_name="prices")
     price = models.FloatField(_(u"Price"), default=0.0)
     priority = models.IntegerField(_(u"Priority"), default=0)
     active = models.BooleanField(_(u"Active"), default=True)
-    criteria_objects = generic.GenericRelation(CriteriaObjects, object_id_field="content_id", content_type_field="content_type")
 
     class Meta:
         ordering = ("priority", )
 
     def __unicode__(self):
         return "%s" % self.price
-
-    def is_valid(self, request, product=None):
-        """
-        The shipping price is valid if it has no criteria or if all assigned
-        criteria are true.
-
-        If product is given the product is tested otherwise the whole cart.
-        """
-        return criteria_utils.is_valid(self, request, product)