Sébastien BEAU - http://www.akretion.com has proposed merging lp:~sebastien.beau/e-commerce-addons/oerp6.1-stable-email-on-exception into lp:e-commerce-addons/oerp6.1-stable.
Requested reviews: extra-addons-commiter (extra-addons-commiter) For more details, see: https://code.launchpad.net/~sebastien.beau/e-commerce-addons/oerp6.1-stable-email-on-exception/+merge/151365 Add the posibility to send on email when an order have an exception -- https://code.launchpad.net/~sebastien.beau/e-commerce-addons/oerp6.1-stable-email-on-exception/+merge/151365 Your team extra-addons-commiter is requested to review the proposed merge of lp:~sebastien.beau/e-commerce-addons/oerp6.1-stable-email-on-exception into lp:e-commerce-addons/oerp6.1-stable.
=== modified file 'sale_exceptions/__openerp__.py' --- sale_exceptions/__openerp__.py 2012-11-21 13:48:17 +0000 +++ sale_exceptions/__openerp__.py 2013-03-02 18:10:17 +0000 @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2011 Akretion LTDA. # authors: Raphaël Valyi, Renato Lima @@ -18,7 +18,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -41,7 +41,9 @@ 'sale_view.xml', 'sale_exceptions_data.xml', 'wizard/sale_exception_confirm_view.xml', - 'security/ir.model.access.csv'], + 'security/ir.model.access.csv', + 'sale_exceptions_mail_template.xml', + ], 'demo_xml': [], 'installable': True, } === modified file 'sale_exceptions/sale.py' --- sale_exceptions/sale.py 2012-12-07 14:11:56 +0000 +++ sale_exceptions/sale.py 2013-03-02 18:10:17 +0000 @@ -5,6 +5,7 @@ # Copyright (C) 2011 Akretion LTDA. # Copyright (C) 2010-2012 Akretion Sébastien BEAU <[email protected]> # Copyright (C) 2012 Camptocamp SA (Guewen Baconnier) +# Copyright (C) 2013 Akretion Chafique DELLI <[email protected]> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -29,6 +30,7 @@ from openerp.osv.osv import except_osv from tools.safe_eval import safe_eval as eval from tools.translate import _ +import logging class sale_exception(Model): _name = "sale.exception" @@ -47,6 +49,8 @@ 'sale_order_ids': fields.many2many('sale.order', 'sale_order_exception_rel', 'exception_id', 'sale_order_id', string='Sale Orders', readonly=True), + 'notif_exception': fields.boolean('Notify exception', + help="If true, a notification will be send by email at the creation of the exception"), } _defaults = { @@ -136,7 +140,9 @@ return True def detect_exceptions(self, cr, uid, ids, context=None): + email_obj = self.pool.get('email.template') exception_obj = self.pool.get('sale.exception') + model_data_obj = self.pool.get('ir.model.data') order_exception_ids = exception_obj.search(cr, uid, [('model', '=', 'sale.order')], context=context) line_exception_ids = exception_obj.search(cr, uid, @@ -151,7 +157,25 @@ continue exception_ids = self._detect_exceptions(cr, uid, order, order_exceptions, line_exceptions, context=context) - + if exception_ids: + notify = False + for exception in exception_obj.browse(cr, uid, exception_ids, context=context): + if exception.notif_exception: + notify = True + if notify: + logger = logging.getLogger(__name__) + model, email_tmpl_id = model_data_obj.get_object_reference( + cr, uid, 'sale_exceptions', + 'email_template_sale_exceptions') + cr.execute('SAVEPOINT send_email') + try: + email_obj.send_mail(cr, uid, email_tmpl_id, + order.id, force_send=True, context=context) + except Exception, e: + logger.exception(e) + cr.execute('ROLLBACK TO SAVEPOINT send_email') + else: + cr.execute('RELEASE SAVEPOINT send_email') self.write(cr, uid, [order.id], {'exceptions_ids': [(6, 0, exception_ids)]}) return exception_ids === added file 'sale_exceptions/sale_exceptions_mail_template.xml' --- sale_exceptions/sale_exceptions_mail_template.xml 1970-01-01 00:00:00 +0000 +++ sale_exceptions/sale_exceptions_mail_template.xml 2013-03-02 18:10:17 +0000 @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + base_external_referentials for OpenERP + Copyright (C) 2013 Akretion Chafique DELLI <[email protected]> + The licence is in the file __openerp__.py +--> +<openerp> + <data noupdate="1"> + + <!--Email template --> + <record id="email_template_sale_exceptions" model="email.template"> + <field name="name">Sale Exception Notification Mail</field> + <field name="email_from">${object.user_id.user_email or ''}</field> + <field name="subject">Exception with Sale Order (Ref ${object.name or 'n/a' })</field> + <field name="email_to">${object.company_id.email}</field> + <field name="model_id" ref="sale.model_sale_order"/> + <field name="auto_delete" eval="False"/> + <field name="lang">${object.company_id.partner_id.lang}</field> + <field name="body_html"><![CDATA[]]></field> + <field name="body_text"><![CDATA[ +An error occurred during the validation of the order ${object.name}. +The exceptions are the followings : + %for exception in object.exceptions_ids: + %if exception.notif_exception: + ${exception.name} + %endif + %endfor]]></field> + </record> + </data> +</openerp> === modified file 'sale_exceptions/sale_view.xml' --- sale_exceptions/sale_view.xml 2012-10-22 14:39:18 +0000 +++ sale_exceptions/sale_view.xml 2013-03-02 18:10:17 +0000 @@ -49,6 +49,7 @@ <group colspan="4" col="2" groups="base.group_system"> <field name="model"/> <field name="code"/> + <field name="notif_exception"/> </group> </group> <group colspan="4" col="2">
-- Mailing list: https://launchpad.net/~savoirfairelinux-openerp Post to : [email protected] Unsubscribe : https://launchpad.net/~savoirfairelinux-openerp More help : https://help.launchpad.net/ListHelp

