~akostajti/openstudio/openstudio

« back to all changes in this revision

Viewing changes to modules/openstudio.py

  • Committer: Edwin van de Ven
  • Date: 2017-02-06 10:48:28 UTC
  • Revision ID: edwinvandeven@home.nl-20170206104828-smxf2aa53udjs7ty
Send mail to customer when recurring paymen fails

Show diffs side-by-side

added added

removed removed

Lines of Context:
705
705
                (db.invoices.SubscriptionMonth == SubscriptionMonth)
706
706
        rows = db(query).select(db.invoices.ALL)
707
707
        if len(rows):
708
 
            return rows.first.id
 
708
            return rows.first().id
709
709
 
710
710
        # Check if the subscription is paused
711
 
        query = (db.customers_subscriptions.paused.Startdate <= lastdaythismonth) & \
 
711
        query = (db.customers_subscriptions_paused.customers_subscriptions_id == self.csID) & \
 
712
                (db.customers_subscriptions_paused.Startdate <= lastdaythismonth) & \
712
713
                ((db.customers_subscriptions_paused.Enddate >= firstdaythismonth) |
713
714
                 (db.customers_subscriptions_paused.Enddate == None))
714
715
        if db(query).count():
716
717
 
717
718
        # Check if an alt. price with amount 0 has been defined
718
719
        csap = db.customers_subscriptions_alt_prices
719
 
        query = (csap.customers_subscriptions_id == csID) & \
 
720
        query = (csap.customers_subscriptions_id == self.csID) & \
720
721
                (csap.SubscriptionYear == SubscriptionYear) & \
721
722
                (csap.SubscriptionMonth == SubscriptionMonth)
722
723
        csap_rows = db(query).select(csap.ALL)
723
724
        if csap_rows:
724
725
            csap_row = csap_rows.first()
725
726
            if csap_row.Amount == 0:
 
727
                #'print casp with 0'
726
728
                return
727
729
 
728
730
        # Ok we've survived all checks, continue with invoice creation
5945
5947
                                           link_profile_invoices=URL('profile', 'invoices', scheme=True, host=True)))
5946
5948
 
5947
5949
 
 
5950
    def _render_email_template_payment_recurring_failed(self, template_content):
 
5951
        '''
 
5952
            :param template_content: html template code from db.sys_properties
 
5953
            :param invoices_id: db.invoices_payments_id
 
5954
            :return: mail body for invoice
 
5955
        '''
 
5956
        db = current.globalenv['db']
 
5957
        T = current.globalenv['T']
 
5958
        DATE_FORMAT = current.globalenv['DATE_FORMAT']
 
5959
 
 
5960
        # TODO: Add to manual & button on page available variables;
 
5961
        return XML(template_content.format(link_profile_invoices=URL('profile', 'invoices', scheme=True, host=True)))
 
5962
 
 
5963
 
5948
5964
    def render_email_template(self,
5949
5965
                              email_template,
5950
5966
                              customers_orders_id=None,
5980
5996
        elif email_template == 'email_template_payment_received':
5981
5997
            subject = T('Payment received')
5982
5998
            content = self._render_email_template_payment(template_content, invoices_payments_id)
 
5999
        elif email_template == 'email_template_payment_recurring_failed':
 
6000
            subject = T('Recurring payment failed')
 
6001
            content = self._render_email_template_payment_recurring_failed(template_content)
5983
6002
        else:
5984
6003
            content = XML(template_content)
5985
6004
            subject = ''