Skip to Content
Menu
This question has been flagged

I created a module inheriting sale.order to add some new statuses and features we use in the company. This is used for orders created from external systems connected to our Odoo instance via the web APIs.

Two new action buttons are made available and work pretty well to have order status to progess: Quotation > Salesperson review > Sales admin review > ... > Sales Order

When moving to the two new statuses, mail notifications are supposed to be sent to the salesperson (when entering "Salesperson review") and to the sales admin (also a res.partener introduced by the module, when entering "Sales admin review").

Below is the code to achieve notifications sending :

    @api.multi
def action_quotation_notify_salesperson(self):
''' Salesperson review '''
self.ensure_one()

if self.state != 'draft':
raise UserError(_('Only draft quotations can be notified'))
elif not self.user_id:
raise UserError(_('A salesperson must be defined in order them to be notified'))

self.message_subscribe_users([self\.user_id\.id\]\)
\ \ \ \ \ \ \ \ self\.message_post\(
\ \ \ \ \ \ \ \ \ \ \ \ _\('This\ online\ quotation\ has\ been\ submitted\ by\ customer\.\ '
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \+\ '%s\ sent\ you\ this\ notification\ in\ order\ you\ review\ and\ validate\ it\.'\)\ %\ self\.env\.user\.display_name,
\ \ \ \ \ \ \ \ \ \ \ \ _\('An\ online\ quotation\ requires\ your\ attention'\),
\ \ \ \ \ \ \ \ \ \ \ \ subtype='mt_comment'
\ \ \ \ \ \ \ \ \)
\ \ \ \ \ \ \ \ return\ self\.write\(\{'state':\ 'wholesales_sales_notified'\}\)

\ \ \ \ @api\.multi
\ \ \ \ def\ action_quotation_notify_sales_admin\(self\):
\ \ \ \ \ \ \ \ ''' Sales\ admin\ review\ '''
\ \ \ \ \ \ \ \ self\.ensure_one\(\)

\ \ \ \ \ \ \ \ if\ self\.state\ !=\ 'wholesales_sales_notified':
\ \ \ \ \ \ \ \ \ \ \ \ raise\ UserError\(_\('Only\ quotations\ reviewed\ by\ salesperson\ can\ be\ notified'\)\)
\ \ \ \ \ \ \ \ elif\ not\ self\.sales_admin_user_id:
\ \ \ \ \ \ \ \ \ \ \ \ raise\ UserError\(_\('A\ sales\ admin\ must\ be\ defined\ in\ order\ them\ to\ be\ notified'\)\)

\ \ \ \ \ \ \ \ self\.message_subscribe_users\(\[self.sales_admin_user_id.id])
self.message_post(
_('This online quotation has been reviewed by salesperson. '
+ '%s sent you this notification in order you review and validate it.') % self.env.user.display_name,
_('An online quotation requires your attention'),
subtype='mt_comment'
)
return self.write({'state': 'wholesales_admin_notified'})

My issue is that notifications are only sent when entering the second status "Sales admin review". For both, the message body is registered in the discution attached to the sale.order object, but for the first "Salesperson review" no mail notification is sent.

Compared to each others from the Settings > Technical > Messages, I can see recipients for both but for the first one the "Sent by mail" field is false / unchecked.

Also, the way functions are called are different. In the first case it's called externally via the web API (XMLRPC), in the second case it's called from Odoo web interface.

Any idea why notifications are not sent by mail ?

Avatar
Discard

There are two options to receive a notification:
Handle by Emails
Handle in Odoo
maybe your first user set his preference to Handle in Odoo

Author

@m-azzain: The user preferences are set as bellow :
Messaging and Social
Email Messages and Notifications Messages : All.

Related Posts Replies Views Activity
0
Nov 24
92
1
Oct 24
262
1
Aug 24
669
1
Apr 24
506
2
Mar 24
731