From db28e23e767e2395f0f0e2d713d5f546f1cbd929 Mon Sep 17 00:00:00 2001
From: Yannick Tivisse
Date: Tue, 23 Aug 2016 16:04:23 +0200
Subject: [PATCH 1/4] [FIX] website_portal_sale: Remove useless/broken link to
backend from my/order,quote
portal_sale: Remove invalid 'get_formview_action' overwrite
This commit https://github.com/odoo/odoo/commit/ecd58457ed2311cfec8cae9d01b04ce995b31ec7 has removed some backend portal actions, but didn't remove them from the template links.
---
addons/portal_sale/models/account_invoice.py | 9 ---------
addons/portal_sale/models/sale_order.py | 10 ----------
addons/website_portal_sale/views/templates.xml | 15 ---------------
3 files changed, 34 deletions(-)
diff --git a/addons/portal_sale/models/account_invoice.py b/addons/portal_sale/models/account_invoice.py
index 75de697483e..628d79d27d3 100644
--- a/addons/portal_sale/models/account_invoice.py
+++ b/addons/portal_sale/models/account_invoice.py
@@ -22,12 +22,3 @@ class AccountInvoice(models.Model):
action='/mail/view',
model=self._name,
res_id=self.id)[self.partner_id.id]
-
- @api.multi
- def get_formview_action(self):
- # NOTE : if this method is call as sudo, the only to determine if the user is portal is to check the uid from context
- # This was introduced with https://github.com/odoo/odoo/commit/f5fedbcb18a57ee9aeab952f3ff95f692f7a863c, and should be better fixed.
- uid = self.env.context.get('uid', self.env.user.id)
- if self.env['res.users'].sudo().browse(uid).share:
- return self.env['ir.actions.act_window'].for_xml_id('portal_sale', 'portal_action_invoices')
- return super(AccountInvoice, self).get_formview_action()
diff --git a/addons/portal_sale/models/sale_order.py b/addons/portal_sale/models/sale_order.py
index f3dc5444d4c..b11d000c125 100644
--- a/addons/portal_sale/models/sale_order.py
+++ b/addons/portal_sale/models/sale_order.py
@@ -22,13 +22,3 @@ class SaleOrder(models.Model):
action='/mail/view',
model=self._name,
res_id=self.id)[self.partner_id.id]
-
- @api.multi
- def get_formview_action(self):
- # NOTE : if this method is call as sudo, the only to determine if the user is portal is to check the uid from context
- # This was introduced with https://github.com/odoo/odoo/commit/f5fedbcb18a57ee9aeab952f3ff95f692f7a863c, and should be better fixed.
- uid = self.env.context.get('uid', self.env.user.id)
- if self.env['res.users'].sudo().browse(uid).share:
- action_xmlid = 'action_quotations_portal' if self.state in ('draft', 'sent') else 'action_orders_portal'
- return self.env['ir.actions.act_window'].for_xml_id('portal_sale', action_xmlid)
- return super(SaleOrder, self).get_formview_action()
diff --git a/addons/website_portal_sale/views/templates.xml b/addons/website_portal_sale/views/templates.xml
index de449b76de8..000ce6c416d 100644
--- a/addons/website_portal_sale/views/templates.xml
+++ b/addons/website_portal_sale/views/templates.xml
@@ -381,19 +381,4 @@
-
-
- Access the complete Sale application
-
-
-
-
-
-
- If you wish to access the complete application to manage your orders, you can follow
- this link.
-
-
-
-
From df802f9005692e3d8d67b24fe149745553eb04b4 Mon Sep 17 00:00:00 2001
From: Yannick Tivisse
Date: Thu, 25 Aug 2016 15:11:01 +0200
Subject: [PATCH 2/4] [FIX] portal_sale: Move portal access rights to
website_portal_sale
Currently as no portal backend view exists anymore, the method 'get_access_action' will return a url to the backend.
For example, if you have only sale installed (with portal_sale in auto install mode), you'll get access rights to sales orders in read mode in backend. The correct way to handle this is to return an access error and give the access rights to these documents only in website_portal_sale is installed, i.e. when the portal view is accessible in frontend under my/orders/ controller.
---
addons/portal_sale/__openerp__.py | 1 -
addons/website_portal_sale/__openerp__.py | 1 +
.../security/ir.model.access.csv | 0
3 files changed, 1 insertion(+), 1 deletion(-)
rename addons/{portal_sale => website_portal_sale}/security/ir.model.access.csv (100%)
diff --git a/addons/portal_sale/__openerp__.py b/addons/portal_sale/__openerp__.py
index 828a41cb232..1095b637c22 100644
--- a/addons/portal_sale/__openerp__.py
+++ b/addons/portal_sale/__openerp__.py
@@ -28,7 +28,6 @@ by default, you simply need to configure a Paypal account in the Accounting/Invo
'depends': ['sale', 'portal', 'payment'],
'data': [
'security/portal_sale_security.xml',
- 'security/ir.model.access.csv',
'views/sale_order_views.xml',
],
'auto_install': True,
diff --git a/addons/website_portal_sale/__openerp__.py b/addons/website_portal_sale/__openerp__.py
index efd132e5bc8..673d1601858 100644
--- a/addons/website_portal_sale/__openerp__.py
+++ b/addons/website_portal_sale/__openerp__.py
@@ -13,6 +13,7 @@ Add your sales document in the frontend portal. Your customers will be able to c
],
'data': [
'views/templates.xml',
+ 'security/ir.model.access.csv',
],
'demo': [
'data/demo.xml'
diff --git a/addons/portal_sale/security/ir.model.access.csv b/addons/website_portal_sale/security/ir.model.access.csv
similarity index 100%
rename from addons/portal_sale/security/ir.model.access.csv
rename to addons/website_portal_sale/security/ir.model.access.csv
From 9a5185500879f8cf77951b7f3fe5d8d19a775f3f Mon Sep 17 00:00:00 2001
From: Yannick Tivisse
Date: Fri, 26 Aug 2016 10:09:00 +0200
Subject: [PATCH 3/4] [FIX] account,sale: Correct management of notifications
to portal users
[FIX] sale: Don't display 'View quotation' button on email if no website
If the website module is not installed, the button 'View Quotation' will lead to the backend chatter page, which is not very useful in our case.
As the quotation is already attached in the mail as a pdf, just don't display the button if the website module is not installed
[FIX] account,sale: Don't send notif template to portal customers if no website
[FIX] account: Don't display 'View Invoice' button on email if no website
If the website module is not installed, the button 'View Invoice' will lead to the backend chatter page, which is not very useful in our case.
As the invoice is already attached in the mail as a pdf, just don't display the button if the website module is not installed
[FIX] website_sale: override get_access_action to redirect to my/invoices
---
addons/account/data/invoice_action_data.xml | 4 +++
addons/account/models/account_invoice.py | 2 ++
addons/sale/data/mail_template_data.xml | 2 ++
addons/sale/sale.py | 3 +-
addons/website_sale/models/__init__.py | 1 +
addons/website_sale/models/account_invoice.py | 31 +++++++++++++++++++
addons/website_sale/models/sale_order.py | 11 +++++++
7 files changed, 53 insertions(+), 1 deletion(-)
create mode 100644 addons/website_sale/models/account_invoice.py
diff --git a/addons/account/data/invoice_action_data.xml b/addons/account/data/invoice_action_data.xml
index d55627d69e1..41d8dea7d6f 100644
--- a/addons/account/data/invoice_action_data.xml
+++ b/addons/account/data/invoice_action_data.xml
@@ -19,6 +19,7 @@
% set access_action = object.get_access_action()
% set access_name = 'View invoice' if access_action and access_action['type'] == 'ir.actions.act_url' else 'See invoice'
% set access_url = access_action['type'] == 'ir.actions.act_url' and access_action['url'] or '/report/pdf/account.report_invoice/' + str(object.id)
+% set is_online = access_action and access_action['type'] == 'ir.actions.act_url'
Dear
% if object.partner_id.is_company and object.child_ids:
@@ -35,9 +36,12 @@ amounting in ${object.amount_total} ${object.currency_id.name}
from ${object.company_id.name}.
+% if is_inline:
${access_name}
+% endif
+
If you have any question, do not hesitate to contact us.
Best regards,
]]>
diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py
index eaec3b34422..8ddfdfe1107 100644
--- a/addons/account/models/account_invoice.py
+++ b/addons/account/models/account_invoice.py
@@ -1069,6 +1069,8 @@ class AccountInvoice(models.Model):
continue
if not recipient.user_ids:
group_data['partner'] |= recipient
+ elif all(recipient.user_ids.mapped('share')):
+ group_data['partner'] |= recipient
else:
group_data['user'] |= recipient
done_ids.add(recipient.id)
diff --git a/addons/sale/data/mail_template_data.xml b/addons/sale/data/mail_template_data.xml
index d9456f28a0a..824aaa3ff84 100644
--- a/addons/sale/data/mail_template_data.xml
+++ b/addons/sale/data/mail_template_data.xml
@@ -36,9 +36,11 @@ amounting in ${object.amount_total} ${object.pricelist_id.currency_id.na
from ${object.company_id.name}.
+% if is_online:
${access_name}
+% endif
If you have any question, do not hesitate to contact us.
Best regards,
]]>
diff --git a/addons/sale/sale.py b/addons/sale/sale.py
index d5b508c8d40..cc88d62c6bc 100644
--- a/addons/sale/sale.py
+++ b/addons/sale/sale.py
@@ -487,12 +487,13 @@ class SaleOrder(models.Model):
@api.multi
def _notification_group_recipients(self, message, recipients, done_ids, group_data):
- group_user = self.env.ref('base.group_user')
for recipient in recipients:
if recipient.id in done_ids:
continue
if not recipient.user_ids:
group_data['partner'] |= recipient
+ elif all(recipient.user_ids.mapped('share')):
+ group_data['partner'] |= recipient
else:
group_data['user'] |= recipient
done_ids.add(recipient.id)
diff --git a/addons/website_sale/models/__init__.py b/addons/website_sale/models/__init__.py
index a40ad2379a6..3f8dbc63ee7 100644
--- a/addons/website_sale/models/__init__.py
+++ b/addons/website_sale/models/__init__.py
@@ -1,3 +1,4 @@
+import account_invoice
import ir_http
import rating
import product
diff --git a/addons/website_sale/models/account_invoice.py b/addons/website_sale/models/account_invoice.py
new file mode 100644
index 00000000000..83fc8f1393a
--- /dev/null
+++ b/addons/website_sale/models/account_invoice.py
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import api, models
+
+
+class AccountInvoice(models.Model):
+ _inherit = 'account.invoice'
+
+ @api.multi
+ def _notification_group_recipients(self, message, recipients, done_ids, group_data):
+ """ Override the method to place the portal customers in the 'user' group data as a portal view now exists"""
+ for recipient in recipients:
+ if recipient.id in done_ids:
+ continue
+ if recipient.user_ids and all(recipient.user_ids.mapped('share')):
+ group_data['user'] |= recipient
+ done_ids.add(recipient.id)
+ return super(AccountInvoice, self)._notification_group_recipients(message, recipients, done_ids, group_data)
+
+ @api.multi
+ 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 invoice if exists. """
+ self.ensure_one()
+ return {
+ 'type': 'ir.actions.act_url',
+ 'url': '/my/invoices', # No controller /my/invoices/, only a report pdf
+ 'target': 'self',
+ 'res_id': self.id,
+ }
diff --git a/addons/website_sale/models/sale_order.py b/addons/website_sale/models/sale_order.py
index 4d58c5c88d3..9271a1db96b 100644
--- a/addons/website_sale/models/sale_order.py
+++ b/addons/website_sale/models/sale_order.py
@@ -123,6 +123,17 @@ class SaleOrder(models.Model):
accessory_products -= order.website_order_line.mapped('product_id')
return random.sample(accessory_products, min(len(accessory_products), 3))
+ @api.multi
+ def _notification_group_recipients(self, message, recipients, done_ids, group_data):
+ """ Override the method to place the portal customers in the 'user' group data as a portal view now exists"""
+ for recipient in recipients:
+ if recipient.id in done_ids:
+ continue
+ if recipient.user_ids and all(recipient.user_ids.mapped('share')):
+ group_data['user'] |= recipient
+ done_ids.add(recipient.id)
+ return super(SaleOrder, self)._notification_group_recipients(message, recipients, done_ids, group_data)
+
class Website(models.Model):
_inherit = 'website'
From b1680bc31941f6f132244241a89b8c3c847cbc05 Mon Sep 17 00:00:00 2001
From: Yannick Tivisse
Date: Fri, 26 Aug 2016 11:47:30 +0200
Subject: [PATCH 4/4] [FIX] project,issue: Correct management of Notifications
to portal users
[FIX] website_project: override get_access_action to redirect to my/tasks,projects
[FIX] project_issue: Don't send notif template to portal customers if no website
[FIX] website_project: Portal users can receive notif template
---
addons/project_issue/models/project_issue.py | 2 +
addons/website_project/__init__.py | 1 +
addons/website_project/models/__init__.py | 4 ++
addons/website_project/models/project.py | 58 +++++++++++++++++++
.../models/project_issue.py | 18 +++++-
5 files changed, 82 insertions(+), 1 deletion(-)
create mode 100644 addons/website_project/models/__init__.py
create mode 100644 addons/website_project/models/project.py
diff --git a/addons/project_issue/models/project_issue.py b/addons/project_issue/models/project_issue.py
index 8d4dacd0caf..ebfa3377e4b 100644
--- a/addons/project_issue/models/project_issue.py
+++ b/addons/project_issue/models/project_issue.py
@@ -259,6 +259,8 @@ class ProjectIssue(models.Model):
group_data['group_project_user'] |= recipient
elif not recipient.user_ids:
group_data['partner'] |= recipient
+ elif all(recipient.user_ids.mapped('share')):
+ group_data['partner'] |= recipient
else:
group_data['user'] |= recipient
done_ids.add(recipient.id)
diff --git a/addons/website_project/__init__.py b/addons/website_project/__init__.py
index bf7fb7b45c1..805c516d376 100644
--- a/addons/website_project/__init__.py
+++ b/addons/website_project/__init__.py
@@ -2,3 +2,4 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import controllers
+import models
\ No newline at end of file
diff --git a/addons/website_project/models/__init__.py b/addons/website_project/models/__init__.py
new file mode 100644
index 00000000000..f08438b04dc
--- /dev/null
+++ b/addons/website_project/models/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+import project
diff --git a/addons/website_project/models/project.py b/addons/website_project/models/project.py
new file mode 100644
index 00000000000..d9a0ae1d0a4
--- /dev/null
+++ b/addons/website_project/models/project.py
@@ -0,0 +1,58 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import api, models
+
+class Project(models.Model):
+ _inherit = ['project.project']
+
+ @api.multi
+ 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 """
+ self.ensure_one()
+ return {
+ 'type': 'ir.actions.act_url',
+ 'url': '/my/project/%s' % self.id,
+ 'target': 'self',
+ 'res_id': self.id,
+ }
+
+ @api.multi
+ def _notification_group_recipients(self, message, recipients, done_ids, group_data):
+ """ Override the method to place the portal customers in the 'user' group data as a portal view now exists"""
+ for recipient in recipients:
+ if recipient.id in done_ids:
+ continue
+ if recipient.user_ids and all(recipient.user_ids.mapped('share')):
+ group_data['user'] |= recipient
+ done_ids.add(recipient.id)
+ return super(Project, self)._notification_group_recipients(message, recipients, done_ids, group_data)
+
+
+class Task(models.Model):
+ _inherit = ['project.task']
+
+ @api.multi
+ 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 """
+ self.ensure_one()
+ return {
+ 'type': 'ir.actions.act_url',
+ 'url': '/my/task/%s' % self.id,
+ 'target': 'self',
+ 'res_id': self.id,
+ }
+
+ @api.multi
+ def _notification_group_recipients(self, message, recipients, done_ids, group_data):
+ """ Override the method to place the portal customers in the 'user' group data as a portal view now exists"""
+ for recipient in recipients:
+ if recipient.id in done_ids:
+ continue
+ if recipient.user_ids and all(recipient.user_ids.mapped('share')):
+ group_data['user'] |= recipient
+ done_ids.add(recipient.id)
+ return super(Task, self)._notification_group_recipients(message, recipients, done_ids, group_data)
+
diff --git a/addons/website_project_issue/models/project_issue.py b/addons/website_project_issue/models/project_issue.py
index a3dd4170826..c47f1edc26a 100644
--- a/addons/website_project_issue/models/project_issue.py
+++ b/addons/website_project_issue/models/project_issue.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-from openerp import _, api, models
+from openerp import api, models
class Issue(models.Model):
@@ -19,3 +19,19 @@ class Issue(models.Model):
'target': 'self',
'res_id': self.id,
}
+
+ @api.multi
+ def _notification_group_recipients(self, message, recipients, done_ids, group_data):
+ """ 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_id = self.env.ref('project.group_project_user').id
+ for recipient in recipients:
+ if recipient.id in done_ids:
+ continue
+ if recipient.user_ids and group_project_user_id in recipient.user_ids[0].groups_id.ids:
+ group_data['group_project_user'] |= recipient
+ elif recipient.user_ids and all(recipient.user_ids.mapped('share')):
+ group_data['user'] |= recipient
+ done_ids.add(recipient.id)
+ return super(Issue, self)._notification_group_recipients(message, recipients, done_ids, group_data)