Ignore:
Timestamp:
3 Feb 2015, 16:54:56 (10 years ago)
Author:
Henrik Bettermann
Message:

Notify customer by email after customer and contract transitions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/utils/utils.py

    r12545 r12553  
    2727from waeup.ikoba.interfaces import MessageFactory as _
    2828from waeup.ikoba.smtp import send_mail as send_mail_internally
    29 from waeup.ikoba.utils.helpers import get_sorted_preferred
     29from waeup.ikoba.utils.helpers import (
     30    get_sorted_preferred, get_current_principal)
    3031from waeup.ikoba.payments.currencies import ISO_4217_CURRENCIES
    3132
     
    241242            subject, body, config)
    242243
    243     def getPaymentItem(self, payment):
    244         """Return payment item.
    245 
    246         This method can be used to customize the display_item property method.
    247         """
    248         return payment.p_item
     244    def sendTransitionInfo(self, customer, obj, msg=None):
     245        """Send transition information as email.
     246
     247        Input is the customer for which credentials are sent and the object
     248        which was transitioned.
     249
     250        Returns True or False to indicate successful operation.
     251        """
     252        config = grok.getSite()['configuration']
     253        if not config.email_notification:
     254            return
     255        subject = 'Ikoba status change information'
     256        text = _(u"""Dear ${a},
     257
     258The status of the following object has been changed:
     259
     260Object Id: ${c}
     261Title: ${d}
     262Transition: ${e}
     263New state: ${f}
     264
     265Regards,
     266
     267${b}
     268
     269--
     270${g}
     271""")
     272        from_name = config.name_admin
     273        from_addr = config.email_admin
     274        rcpt_name = customer.title
     275        rcpt_addr = customer.email
     276
     277        user = get_current_principal()
     278        if user is None:
     279            usertitle = 'system'
     280        elif user.id == 'zope.anybody':
     281            usertitle = 'Anonymous'
     282        else:
     283            usertitle = getattr(user, 'public_name', None)
     284            if not usertitle:
     285                usertitle = user.title
     286
     287        msg = translate(msg,'waeup.ikoba', target_language=self.PORTAL_LANGUAGE)
     288        new_state = translate(obj.translated_state,'waeup.ikoba',
     289            target_language=self.PORTAL_LANGUAGE)
     290
     291        text = _(text, mapping={
     292            'a': rcpt_name,
     293            'b': usertitle,
     294            'c': obj.__name__,
     295            'd': obj.title,
     296            'e': msg.lower(),
     297            'f': new_state,
     298            'g': config.name})
     299
     300        body = translate(text, 'waeup.ikoba',
     301            target_language=self.PORTAL_LANGUAGE)
     302
     303        return send_mail(
     304            from_name, from_addr, rcpt_name, rcpt_addr,
     305            subject, body, config)
    249306
    250307    def expensive_actions_allowed(self, type=None, request=None):
Note: See TracChangeset for help on using the changeset viewer.