Help

1

Don't send automatic e-mail when confirming quotation?

Hi guys,

When you have portal activated you'll get an automatic e-mail saying something along these lines:

 Quotation confirmed
    • Customer: Yenthe
    • Untaxed Amount: 1.

The problem is that I do not want this message to be e-mailed. Any message should be e-mailed to the customer when the portal is active, except this one.
The message is made by the function format_message in mail/mail_thread.py:

 def format_message(message_description, tracked_values):
            message = ''
            if message_description:
                message = '<span>%s</span>' % message_description
            for name, change in tracked_values.items():
                message += '<div> &nbsp; &nbsp; &bull; <b>%s</b>: ' % change.get('col_info')
                if change.get('old_value'):
                    message += '%s &rarr; ' % change.get('old_value')
                message += '%s</div>' % change.get('new_value')
            return message
        if not tracked_fields:
            return True

This function posts the message to the view (in the chatter) but the problem is that somewhere else an action is triggered to send this message as an e-mail to the user.

So, my question, how can I / what is the best way to prevent this message to be send by email but allow anything else to be e-mailed to the customers?

Thanks,
Yenthe

Avatar
Discard
3 Answers
0

Hi guys,

Found the solution myself. In the module mail is a Python file named mail_thread. In mail_thread.py is a function def message_track(self, cr, uid, ids, tracked_fields, initial_values, context=None): and inside this function you will find the following code:

 for subtype in subtypes:
                subtype_rec = self.pool.get('ir.model.data').xmlid_to_object(cr, uid, subtype, context=context)
                if not (subtype_rec and subtype_rec.exists()):
                    _logger.debug('subtype %s not found' % subtype)
                    continue
                message = format_message(subtype_rec.description if subtype_rec.description else subtype_rec.name, tracked_values)
                self.message_post(cr, uid, browse_record.id, body=message, subtype=subtype, context=context)
                posted = True
            if not posted:
                message = format_message('', tracked_values)
                self.message_post(cr, uid, browse_record.id, body=message, context=context)

When you change the message variable in the first if condition there will be no more automatic messages e-mailed, not even when the portal is activated.Result:

 for subtype in subtypes:
                subtype_rec = self.pool.get('ir.model.data').xmlid_to_object(cr, uid, subtype, context=context)
                if not (subtype_rec and subtype_rec.exists()):
                    _logger.debug('subtype %s not found' % subtype)
                    continue
                message = format_message('', tracked_values)
                self.message_post(cr, uid, browse_record.id, body=message, context=context)
                posted = True
            if not posted:
                message = format_message('', tracked_values)
                self.message_post(cr, uid, browse_record.id, body=message, context=context)
Avatar
Discard
0
Avatar
Axel Mendoza
Best Answer

You could read more about that here:

https://www.odoo.com/es_ES/forum/help-1/question/adding-messages-subtypes-for-product-changes-v7-91170#answer-91171

In your case you could disable that tracking of the needed fields just defining the field name in the _track dict with a lambda function that returns False like:

_track = {
    'field': {
'sale.mt_quotation.anything': lambda self, cr, uid, obj, ctx=None: False,
}
}
4 Comments
Avatar
Discard
Avatar
Axel Mendoza
-

it will have the same results like you have with the change, the difference is that you need to define all the field tracked in your model in the _track dict

Avatar
Ehtesham
-

I am facing the same issue, I want to mute only email for this subtype message "Quotation Confirmed". Trying your method now.

Avatar
Ehtesham
-

Thanks, I just tried and it works as expected however I don't want to include all fields in my child model. I just want 'sale.mt_order_confirmed' to be set false. So in my child model instead of this _track = { 'state': { 'sale.mt_order_confirmed': lambda self, cr, uid, obj, ctx=None: False, 'sale.mt_order_sent': lambda self, cr, uid, obj, ctx=None: obj.state in ['sent'] }, } I want something like this _track['state']['sale.mt_order_confirmed'] = lambda self, cr, uid, obj, ctx=None: False Excuse my syntax I am new to Python, I just want to change the targeted field's specific state. just to be future proof.

Avatar
Axel Mendoza
-

Then you are ready to vote the answer :). The other scenario that you describe require the extension of the message_track method in your model extension to support that behavior

0
Best Answer

If anyone wants to prevent from sending quotations (no matter if it's a portal-user or not) you can use this:


class NoQuotationSaleOrder(models.Model):
_inherit = 'sale.order'

@api.multi
def action_quotation_send(self):
self.ensure_one()

if self.state != "sale":
return False

# Use this if you want to use the access token in your email-template:
self._portal_ensure_token()

return super(NoQuotationSaleOrder, self).action_quotation_send()


Avatar
Discard