[FIX] hr_holidays: mailing deadlock / spam

Some fixes coming from V9 revision 2be1dfc1ed7c9814cd3dbf4eb4cc95f842f738c2. The
purpose is to avoid to send emails in batch and to limitate automatic
subscription.

 - add a context key to use the email queue for notifications linked
   to allocations created in batch. This way emails will be send asynchronously
   and will not create a deadlock when having a lot of allocations to process.
 - also fixed a missing context in a browse
This commit is contained in:
Thibault Delavallée 2015-11-18 15:57:57 +01:00
parent 6f29cbe3ac
commit e74c12ffe2
1 changed files with 4 additions and 3 deletions

View File

@ -325,7 +325,7 @@ class hr_holidays(osv.osv):
""" Override to avoid automatic logging of creation """
if context is None:
context = {}
context = dict(context, mail_create_nolog=True)
context = dict(context, mail_create_nolog=True, mail_create_nosubscribe=True)
if values.get('state') and values['state'] not in ['draft', 'confirm', 'cancel'] and not self.pool['res.users'].has_group(cr, uid, 'base.group_hr_user'):
raise osv.except_osv(_('Warning!'), _('You cannot set a leave request as \'%s\'. Contact a human resource manager.') % values.get('state'))
return super(hr_holidays, self).create(cr, uid, values, context=context)
@ -393,7 +393,8 @@ class hr_holidays(osv.osv):
elif record.holiday_type == 'category':
emp_ids = obj_emp.search(cr, uid, [('category_ids', 'child_of', [record.category_id.id])])
leave_ids = []
for emp in obj_emp.browse(cr, uid, emp_ids):
batch_context = dict(context, mail_notify_force_send=False)
for emp in obj_emp.browse(cr, uid, emp_ids, context=context):
vals = {
'name': record.name,
'type': record.type,
@ -406,7 +407,7 @@ class hr_holidays(osv.osv):
'parent_id': record.id,
'employee_id': emp.id
}
leave_ids.append(self.create(cr, uid, vals, context=None))
leave_ids.append(self.create(cr, uid, vals, context=batch_context))
for leave_id in leave_ids:
# TODO is it necessary to interleave the calls?
for sig in ('confirm', 'validate', 'second_validate'):