From: Benoît Pin Date: Thu, 4 Sep 2014 21:18:05 +0000 (+0200) Subject: Implémentation de la remise. X-Git-Url: https://scm.cri.mines-paristech.fr/git/photoprint.git/commitdiff_plain/e4159a95428accbd43f91f44d568d7afff72fc95?hp=4bb6988027b9396a5f0ed10509f15dc2a230c61c Implémentation de la remise. --- diff --git a/order.py b/order.py index db19cc0..6966ff3 100755 --- a/order.py +++ b/order.py @@ -183,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() @@ -192,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') @@ -223,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 : @@ -251,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, '') diff --git a/skins/order_view.py b/skins/order_view.py index 308844c..1930d31 100755 --- a/skins/order_view.py +++ b/skins/order_view.py @@ -55,6 +55,7 @@ for item in context.items : options['infos'] = infos options['quantity'] = quantity options['pricesSum'] = context.price +options['discount'] = getattr(context, 'discount', 0) options['shippingFees'] = shippingFees = context.shippingFees options['total'] = context.amountWithFees diff --git a/skins/order_view_template.pt b/skins/order_view_template.pt index 5f748b2..96e6c4a 100644 --- a/skins/order_view_template.pt +++ b/skins/order_view_template.pt @@ -129,6 +129,10 @@ + + Discount + % + Shipping