X-Git-Url: https://svn.cri.ensmp.fr/git/photoprint.git/blobdiff_plain/3af5cd787b12ad1a54f05f37cfa729f073e08ad4..refs/heads/zope-2.13:/order.py diff --git a/order.py b/order.py index ea48483..6966ff3 100755 --- a/order.py +++ b/order.py @@ -45,7 +45,11 @@ from price import Price from xml.dom.minidom import Document from tool import COPIES_COUNTERS from App.config import getConfiguration -from paypal.interface import PayPalInterface +try : + from paypal.interface import PayPalInterface + paypalAvailable = True +except ImportError : + paypalAvailable = False from logging import getLogger console = getLogger('Products.photoprint.order') @@ -179,6 +183,7 @@ class PrintOrder(PortalContent, DefaultDublinCoreImpl) : self.id = id self.items = [] self.quantity = 0 + self.discount = 0 # discount ratio in percent self.price = Price(0, 0) # billing and shipping addresses self.billing = PersistentMapping() @@ -188,7 +193,8 @@ class PrintOrder(PortalContent, DefaultDublinCoreImpl) : @property def amountWithFees(self) : - return self.price + self.shippingFees + coeff = (100 - self.discount) / 100. + return self.price * coeff + self.shippingFees security.declareProtected(ModifyPortalContent, 'editBilling') @@ -219,6 +225,7 @@ class PrintOrder(PortalContent, DefaultDublinCoreImpl) : pptool = getToolByName(self, 'portal_photo_print') uidh = getToolByName(self, 'portal_uidhandler') mtool = getToolByName(self, 'portal_membership') + utool = getToolByName(self, 'portal_url') items = [] for item in cart : @@ -247,6 +254,9 @@ class PrintOrder(PortalContent, DefaultDublinCoreImpl) : counters.confirm(reference, quantity) self.items = tuple(items) + discount_script = getattr(utool.getPortalObject(), 'photoprint_discount', None) + if discount_script : + self.discount = discount_script(self.price, self.quantity) member = mtool.getAuthenticatedMember() mg = lambda name : member.getProperty(name, '') @@ -333,12 +343,12 @@ class PrintOrder(PortalContent, DefaultDublinCoreImpl) : } if len(self.items) > 1 : - quantitySum = reduce(lambda a, b : a['quantity'] + b['quantity'], self.items) + quantitySum = reduce(lambda a, b : a + b, [item['quantity'] for item in self.items]) else : quantitySum = self.items[0]['quantity'] total = round(self.amountWithFees.getValues()['taxed'], 2) - options['L_PAYMENTREQUEST_0_NAME0'] = 'Commande realis photo ref. %s' % self.getId() + options['L_PAYMENTREQUEST_0_NAME0'] = 'Commande photo ref. %s' % self.getId() if quantitySum == 1 : options['L_PAYMENTREQUEST_0_DESC0'] = "Commande d'un tirage photographique" else :