summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Delavallée <tde@openerp.com>2015-08-26 15:18:36 +0200
committerThibault Delavallée <tde@openerp.com>2015-08-28 17:36:16 +0200
commit59c5ff08beb07d455f1e0d5eaa072c784949d3be (patch)
tree9e42938fe355285c755ac963464c4d8731b1d59a
parent01ab75f597d6ff8f3f570b4c316179654caf7b1c (diff)
[IMP] various: action buttons in notifications
Main addons updated : - crm: Conversion and Won / Lost actions - hr_holidays: Approve / Refuse for hr users / officers - project: Assign / New (task and issues) - forum, website_project_issue, website_portal_sale: go to the website view
-rw-r--r--addons/crm/crm_lead.py34
-rw-r--r--addons/hr_expense/hr_expense.py32
-rw-r--r--addons/hr_holidays/hr_holidays.py32
-rw-r--r--addons/note/note.py9
-rw-r--r--addons/project/project.py31
-rw-r--r--addons/project_issue/project_issue.py32
-rw-r--r--addons/website_blog/models/website_blog.py21
-rw-r--r--addons/website_forum/models/forum.py11
-rw-r--r--addons/website_portal_sale/__init__.py4
-rw-r--r--addons/website_portal_sale/models/__init__.py4
-rw-r--r--addons/website_portal_sale/models/sale_order.py19
-rw-r--r--addons/website_project_issue/__init__.py1
-rw-r--r--addons/website_project_issue/models/__init__.py4
-rw-r--r--addons/website_project_issue/models/project_issue.py31
14 files changed, 263 insertions, 2 deletions
diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py
index 4f38d41e933..2adf9fb84e4 100644
--- a/addons/crm/crm_lead.py
+++ b/addons/crm/crm_lead.py
@@ -5,8 +5,8 @@ from datetime import datetime, timedelta, date
from dateutil.relativedelta import relativedelta
import logging
from operator import itemgetter
+from werkzeug import url_encode
-import openerp
from openerp import SUPERUSER_ID
from openerp import tools, api
from openerp.addons.base.res.res_partner import format_address
@@ -935,6 +935,38 @@ Update your business card, phone book, social media,... Send an email right now
return 'crm.mt_lead_stage'
return super(crm_lead, self)._track_subtype(cr, uid, ids, init_values, context=context)
+ def _notification_group_recipients(self, cr, uid, ids, message, recipients, done_ids, group_data, context=None):
+ """ Override the mail.thread method to handle salesman recipients.
+ Indeed those will have specific action in their notification emails. """
+ group_sale_salesman = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'base.group_sale_salesman')
+ for recipient in recipients:
+ if recipient.id in done_ids:
+ continue
+ if recipient.user_ids and group_sale_salesman in recipient.user_ids[0].groups_id.ids:
+ group_data['group_sale_salesman'] |= recipient
+ done_ids.add(recipient.id)
+ return super(crm_lead, self)._notification_group_recipients(cr, uid, ids, message, recipients, done_ids, group_data, context=context)
+
+ def _notification_get_recipient_groups(self, cr, uid, ids, message, recipients, context=None):
+ res = super(crm_lead, self)._notification_get_recipient_groups(cr, uid, ids, message, recipients, context=context)
+
+ won_action = self._notification_link_helper(cr, uid, ids, 'method', context=context, method='case_mark_won')
+ lost_action = self._notification_link_helper(cr, uid, ids, 'method', context=context, method='case_mark_lost')
+ convert_action = self._notification_link_helper(cr, uid, ids, 'method', context=context, method='convert_opportunity')
+
+ lead = self.browse(cr, uid, ids[0], context=context)
+ if lead.type == 'lead':
+ res['group_sale_salesman'] = {
+ 'actions': [{'url': convert_action, 'title': 'Convert to opportunity'}]
+ }
+ else:
+ res['group_sale_salesman'] = {
+ 'actions': [
+ {'url': won_action, 'title': 'Won'},
+ {'url': lost_action, 'title': 'Lost'}]
+ }
+ return res
+
@api.cr_uid_context
def message_get_reply_to(self, cr, uid, ids, default=None, context=None):
""" Override to get the reply_to of the parent project. """
diff --git a/addons/hr_expense/hr_expense.py b/addons/hr_expense/hr_expense.py
index 0f0de3f4d21..b8f955a0048 100644
--- a/addons/hr_expense/hr_expense.py
+++ b/addons/hr_expense/hr_expense.py
@@ -154,6 +154,38 @@ class hr_expense_expense(osv.osv):
return 'hr_expense.mt_expense_refused'
return super(hr_expense_expense, self)._track_subtype(cr, uid, ids, init_values, context=context)
+ def _notification_group_recipients(self, cr, uid, ids, message, recipients, done_ids, group_data, context=None):
+ """ Override because HR users / officers can approve / refuse expenses
+ directly form their notification email. """
+ group_hr_user = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'base.group_hr_user')
+ for recipient in recipients:
+ if recipient.id in done_ids:
+ continue
+ if recipient.user_ids and group_hr_user in recipient.user_ids[0].groups_id.ids:
+ group_data['group_hr_user'] |= recipient
+ done_ids.add(recipient.id)
+ return super(hr_expense_expense, self)._notification_group_recipients(cr, uid, ids, message, recipients, done_ids, group_data, context=context)
+
+ def _notification_get_recipient_groups(self, cr, uid, ids, message, recipients, context=None):
+ """ Override because HR users / officers can approve / refuse expenses
+ directly form their notification email. """
+ res = super(hr_expense_expense, self)._notification_get_recipient_groups(cr, uid, ids, message, recipients, context=context)
+
+ app_action = self._notification_link_helper(cr, uid, ids, 'workflow', context=context, signal='validate')
+ ref_action = self._notification_link_helper(cr, uid, ids, 'workflow', context=context, signal='refuse')
+
+ expense = self.browse(cr, uid, ids[0], context=context)
+ actions = []
+ if expense.state == 'confirm':
+ actions.append({'url': app_action, 'title': _('Approve')})
+ if expense.state in ['confirm', 'accepted']:
+ actions.append({'url': ref_action, 'title': _('Refuse')})
+
+ res['group_hr_user'] = {
+ 'actions': actions
+ }
+ return res
+
def account_move_get(self, cr, uid, expense_id, context=None):
'''
This method prepare the creation of the account move related to the given expense.
diff --git a/addons/hr_holidays/hr_holidays.py b/addons/hr_holidays/hr_holidays.py
index 664a5169647..fe401e6ca5a 100644
--- a/addons/hr_holidays/hr_holidays.py
+++ b/addons/hr_holidays/hr_holidays.py
@@ -11,6 +11,7 @@ import logging
import math
import time
from operator import attrgetter
+from werkzeug import url_encode
from dateutil.relativedelta import relativedelta
@@ -487,6 +488,37 @@ class hr_holidays(osv.osv):
return 'hr_holidays.mt_holidays_refused'
return super(hr_holidays, self)._track_subtype(cr, uid, ids, init_values, context=context)
+ def _notification_group_recipients(self, cr, uid, ids, message, recipients, done_ids, group_data, context=None):
+ """ Override the mail.thread method to handle HR users and officers
+ recipients. Indeed those will have specific action in their notification
+ emails. """
+ group_hr_user = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'base.group_hr_user')
+ for recipient in recipients:
+ if recipient.id in done_ids:
+ continue
+ if recipient.user_ids and group_hr_user in recipient.user_ids[0].groups_id.ids:
+ group_data['group_hr_user'] |= recipient
+ done_ids.add(recipient.id)
+ return super(hr_holidays, self)._notification_group_recipients(cr, uid, ids, message, recipients, done_ids, group_data, context=context)
+
+ def _notification_get_recipient_groups(self, cr, uid, ids, message, recipients, context=None):
+ res = super(hr_holidays, self)._notification_get_recipient_groups(cr, uid, ids, message, recipients, context=context)
+
+ app_action = '/mail/workflow?%s' % url_encode({'model': self._name, 'res_id': ids[0], 'signal': 'validate'})
+ ref_action = '/mail/workflow?%s' % url_encode({'model': self._name, 'res_id': ids[0], 'signal': 'refuse'})
+
+ holiday = self.browse(cr, uid, ids[0], context=context)
+ actions = []
+ if holiday.state == 'confirm':
+ actions.append({'url': app_action, 'title': 'Approve'})
+ if holiday.state in ['confirm', 'validate', 'validate1']:
+ actions.append({'url': ref_action, 'title': 'Refuse'})
+
+ res['group_hr_user'] = {
+ 'actions': actions
+ }
+ return res
+
class resource_calendar_leaves(osv.osv):
_inherit = "resource.calendar.leaves"
diff --git a/addons/note/note.py b/addons/note/note.py
index b2ba017bbd1..be2a51ceb46 100644
--- a/addons/note/note.py
+++ b/addons/note/note.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-from openerp import SUPERUSER_ID
+from openerp import _, SUPERUSER_ID
from openerp.osv import osv, fields
from openerp.tools import html2plaintext
@@ -156,6 +156,13 @@ class note_note(osv.osv):
return super(note_note, self).read_group(cr, uid, domain, fields, groupby,
offset=offset, limit=limit, context=context, orderby=orderby,lazy=lazy)
+ def _notification_get_recipient_groups(self, cr, uid, ids, message, recipients, context=None):
+ res = super(note_note, self)._notification_get_recipient_groups(cr, uid, ids, message, recipients, context=context)
+ res['user'] = {
+ 'actions': [{'url': self._notification_link_helper(cr, uid, ids, 'new', context=context), 'title': _('New Note')}]
+ }
+ return res
+
class res_users(osv.Model):
_name = 'res.users'
diff --git a/addons/project/project.py b/addons/project/project.py
index 04ca02dcdbe..e7292f62a8e 100644
--- a/addons/project/project.py
+++ b/addons/project/project.py
@@ -752,6 +752,37 @@ class task(osv.osv):
return 'project.mt_task_stage'
return super(task, self)._track_subtype(cr, uid, ids, init_values, context=context)
+ def _notification_group_recipients(self, cr, uid, ids, message, recipients, done_ids, group_data, context=None):
+ """ Override the mail.thread method to handle project users and officers
+ recipients. Indeed those will have specific action in their notification
+ emails: creating tasks, assigning it. """
+ group_project_user = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'project.group_project_user')
+ for recipient in recipients:
+ if recipient.id in done_ids:
+ continue
+ if recipient.user_ids and group_project_user in recipient.user_ids[0].groups_id.ids:
+ group_data['group_project_user'] |= recipient
+ done_ids.add(recipient.id)
+ return super(task, self)._notification_group_recipients(cr, uid, ids, message, recipients, done_ids, group_data, context=context)
+
+ def _notification_get_recipient_groups(self, cr, uid, ids, message, recipients, context=None):
+ res = super(task, self)._notification_get_recipient_groups(cr, uid, ids, message, recipients, context=context)
+
+ take_action = self._notification_link_helper(cr, uid, ids, 'assign', context=context)
+ new_action = self._notification_link_helper(cr, uid, ids, 'new', context=context, view_xmlid='project.action_view_task')
+
+ task_record = self.browse(cr, uid, ids[0], context=context)
+ actions = []
+ if not task_record.user_id:
+ actions.append({'url': take_action, 'title': _('I take it')})
+ else:
+ actions.append({'url': new_action, 'title': _('New Task')})
+
+ res['group_project_user'] = {
+ 'actions': actions
+ }
+ return res
+
@api.cr_uid_context
def message_get_reply_to(self, cr, uid, ids, default=None, context=None):
""" Override to get the reply_to of the parent project. """
diff --git a/addons/project_issue/project_issue.py b/addons/project_issue/project_issue.py
index b336299c3db..09f24792656 100644
--- a/addons/project_issue/project_issue.py
+++ b/addons/project_issue/project_issue.py
@@ -316,6 +316,38 @@ class project_issue(osv.Model):
return 'project_issue.mt_issue_stage'
return super(project_issue, self)._track_subtype(cr, uid, ids, init_values, context=context)
+ def _notification_group_recipients(self, cr, uid, ids, message, recipients, done_ids, group_data, context=None):
+ """ Override the mail.thread method to handle project users and officers
+ recipients. Indeed those will have specific action in their notification
+ emails: creating tasks, assigning it. """
+ group_project_user = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'project.group_project_user')
+ for recipient in recipients:
+ if recipient.id in done_ids:
+ continue
+ if recipient.user_ids and group_project_user in recipient.user_ids[0].groups_id.ids:
+ group_data['group_project_user'] |= recipient
+ done_ids.add(recipient.id)
+ return super(project_issue, self)._notification_group_recipients(cr, uid, ids, message, recipients, done_ids, group_data, context=context)
+
+ def _notification_get_recipient_groups(self, cr, uid, ids, message, recipients, context=None):
+ res = super(project_issue, self)._notification_get_recipient_groups(cr, uid, ids, message, recipients, context=context)
+
+ new_action_id = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'project_issue.project_issue_categ_act0')
+ take_action = self._notification_link_helper(cr, uid, ids, 'assign', context=context)
+ new_action = self._notification_link_helper(cr, uid, ids, 'new', context=context, view_id=new_action_id)
+
+ task_record = self.browse(cr, uid, ids[0], context=context)
+ actions = []
+ if not task_record.user_id:
+ actions.append({'url': take_action, 'title': _('I take it')})
+ else:
+ actions.append({'url': new_action, 'title': _('New Issue')})
+
+ res['group_project_user'] = {
+ 'actions': actions
+ }
+ return res
+
@api.cr_uid_context
def message_get_reply_to(self, cr, uid, ids, default=None, context=None):
""" Override to get the reply_to of the parent project. """
diff --git a/addons/website_blog/models/website_blog.py b/addons/website_blog/models/website_blog.py
index 90e2a90a340..a253871b4b6 100644
--- a/addons/website_blog/models/website_blog.py
+++ b/addons/website_blog/models/website_blog.py
@@ -245,6 +245,27 @@ class BlogPost(osv.Model):
self._check_for_publication(cr, uid, ids, vals, context=context)
return result
+ def get_access_action(self, cr, uid, id, context=None):
+ """ Override method that generated the link to access the document. Instead
+ of the classic form view, redirect to the post on the website directly """
+ post = self.browse(cr, uid, id, context=context)
+ return {
+ 'type': 'ir.actions.act_url',
+ 'url': '/blog/%s/post/%s' % (post.blog_id.id, post.id),
+ 'target': 'self',
+ 'res_id': self.id,
+ }
+
+ def _notification_get_recipient_groups(self, cr, uid, ids, message, recipients, context=None):
+ """ Override to set the access button: everyone can see an access button
+ on their notification email. It will lead on the website view of the
+ post. """
+ res = super(BlogPost, self)._notification_get_recipient_groups(cr, uid, ids, message, recipients, context=context)
+ access_action = self._notification_link_helper('view', model=message.model, res_id=message.res_id)
+ for category, data in res.iteritems():
+ res[category]['button_access'] = {'url': access_action, 'title': _('View Blog Post')}
+ return res
+
class Website(osv.Model):
_inherit = "website"
diff --git a/addons/website_forum/models/forum.py b/addons/website_forum/models/forum.py
index 410dbd46ee5..7da1e16acf1 100644
--- a/addons/website_forum/models/forum.py
+++ b/addons/website_forum/models/forum.py
@@ -626,6 +626,17 @@ class Post(models.Model):
'res_id': self.id,
}
+ @api.multi
+ def _notification_get_recipient_groups(self, message, recipients):
+ """ Override to set the access button: everyone can see an access button
+ on their notification email. It will lead on the website view of the
+ post. """
+ res = super(Post, self)._notification_get_recipient_groups(message, recipients)
+ access_action = self._notification_link_helper('view', model=message.model, res_id=message.res_id)
+ for category, data in res.iteritems():
+ res[category]['button_access'] = {'url': access_action, 'title': '%s %s' % (_('View'), self.post_type)}
+ return res
+
@api.cr_uid_ids_context
def message_post(self, cr, uid, thread_id, message_type='notification', subtype=None, context=None, **kwargs):
if thread_id and message_type == 'comment': # user comments have a restriction on karma
diff --git a/addons/website_portal_sale/__init__.py b/addons/website_portal_sale/__init__.py
index ee5959455ad..ac0011716f6 100644
--- a/addons/website_portal_sale/__init__.py
+++ b/addons/website_portal_sale/__init__.py
@@ -1 +1,5 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
import controllers
+import models
diff --git a/addons/website_portal_sale/models/__init__.py b/addons/website_portal_sale/models/__init__.py
new file mode 100644
index 00000000000..76bcb3512a1
--- /dev/null
+++ b/addons/website_portal_sale/models/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+import sale_order
diff --git a/addons/website_portal_sale/models/sale_order.py b/addons/website_portal_sale/models/sale_order.py
new file mode 100644
index 00000000000..c39c90521ef
--- /dev/null
+++ b/addons/website_portal_sale/models/sale_order.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from openerp import api, models
+
+
+class sale_order(models.Model):
+ _inherit = 'sale.order'
+
+ @api.one
+ def get_access_action(self):
+ """ Override method that generated the link to access the document. Instead
+ of the classic form view, redirect to the online quote if exists. """
+ return {
+ 'type': 'ir.actions.act_url',
+ 'url': '/my/orders/%s' % self.id,
+ 'target': 'self',
+ 'res_id': self.id,
+ }
diff --git a/addons/website_project_issue/__init__.py b/addons/website_project_issue/__init__.py
index bf7fb7b45c1..ac0011716f6 100644
--- a/addons/website_project_issue/__init__.py
+++ b/addons/website_project_issue/__init__.py
@@ -2,3 +2,4 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import controllers
+import models
diff --git a/addons/website_project_issue/models/__init__.py b/addons/website_project_issue/models/__init__.py
new file mode 100644
index 00000000000..8f683c5dcd7
--- /dev/null
+++ b/addons/website_project_issue/models/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+import project_issue
diff --git a/addons/website_project_issue/models/project_issue.py b/addons/website_project_issue/models/project_issue.py
new file mode 100644
index 00000000000..9344157422c
--- /dev/null
+++ b/addons/website_project_issue/models/project_issue.py
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from openerp import _, api, models
+
+
+class Issue(models.Model):
+ _name = "project.issue"
+ _inherit = ['project.issue']
+
+ @api.one
+ def get_access_action(self):
+ """ Override method that generated the link to access the document. Instead
+ of the classic form view, redirect to the post on the website directly """
+ return {
+ 'type': 'ir.actions.act_url',
+ 'url': '/my/issues/%s' % self.id,
+ 'target': 'self',
+ 'res_id': self.id,
+ }
+
+ @api.multi
+ def _notification_get_recipient_groups(self, message, recipients):
+ """ Override to set the access button: everyone can see an access button
+ on their notification email. It will lead on the website view of the
+ post. """
+ res = super(Issue, self)._notification_get_recipient_groups(message, recipients)
+ access_action = self._notification_link_helper('view', model=message.model, res_id=message.res_id)
+ for category, data in res.iteritems():
+ res[category]['button_access'] = {'url': access_action, 'title': _('View Issue')}
+ return res