Implémentation de la remise.
authorBenoît Pin <benoit.pin@gmail.com>
Thu, 4 Sep 2014 21:18:05 +0000 (23:18 +0200)
committerBenoît Pin <benoit.pin@gmail.com>
Thu, 4 Sep 2014 21:18:05 +0000 (23:18 +0200)
order.py
skins/order_view.py
skins/order_view_template.pt

index db19cc0..6966ff3 100755 (executable)
--- a/order.py
+++ b/order.py
@@ -183,6 +183,7 @@ class PrintOrder(PortalContent, DefaultDublinCoreImpl) :
         self.id = id
         self.items = []
         self.quantity = 0
         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()
         self.price = Price(0, 0)
         # billing and shipping addresses
         self.billing = PersistentMapping()
@@ -192,7 +193,8 @@ class PrintOrder(PortalContent, DefaultDublinCoreImpl) :
     
     @property
     def amountWithFees(self) :
     
     @property
     def amountWithFees(self) :
-        return self.price + self.shippingFees
+        coeff = (100 - self.discount) / 100.
+        return self.price * coeff + self.shippingFees
     
     
     security.declareProtected(ModifyPortalContent, 'editBilling')
     
     
     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')
         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 :
         
         items = []
         for item in cart :
@@ -251,6 +254,9 @@ class PrintOrder(PortalContent, DefaultDublinCoreImpl) :
                 counters.confirm(reference, quantity)
                 
         self.items = tuple(items)
                 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, '')
 
         member = mtool.getAuthenticatedMember()
         mg = lambda name : member.getProperty(name, '')
index 308844c..1930d31 100755 (executable)
@@ -55,6 +55,7 @@ for item in context.items :
 options['infos'] = infos
 options['quantity'] = quantity
 options['pricesSum'] = context.price
 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
 
 options['shippingFees'] = shippingFees = context.shippingFees
 options['total'] = context.amountWithFees
 
index 5f748b2..96e6c4a 100644 (file)
             <th class="num" tal:content="python:'%s €' % options['pricesSum'].taxed"
                 style="border-right:1px solid black"></th>
           </tr>
             <th class="num" tal:content="python:'%s €' % options['pricesSum'].taxed"
                 style="border-right:1px solid black"></th>
           </tr>
+          <tr tal:condition="options/discount">
+            <td class="num" colspan="5" i18n:translate="">Discount</td>
+            <td class="num"><span tal:replace="options/discount"/> %</td>
+          </tr>
           <tr>
             <td class="num" colspan="5" i18n:translate="">Shipping</td>
             <td class="num" tal:content="python:'%s €' % options['shippingFees'].taxed"></td>
           <tr>
             <td class="num" colspan="5" i18n:translate="">Shipping</td>
             <td class="num" tal:content="python:'%s €' % options['shippingFees'].taxed"></td>