summaryrefslogtreecommitdiff
path: root/addons/website_mail/models
diff options
context:
space:
mode:
authorKeyur Gajjar <kga@odoo.com>2015-08-20 15:16:03 +0530
committerJérome Maes <jem@openerp.com>2016-04-13 11:20:53 +0200
commit30f48eb6b677105c47f67d66a71b1102cafbb558 (patch)
treec07109e1a159c812cd7dba403404905a5c92568e /addons/website_mail/models
parentd672d8aa867140bec8bd3a3a2f89e22fb9f14364 (diff)
[MIG] website_mail: code migration to new api
No functional changes, only rewrite the code with the api.v8 which more pythonic and smooth.
Diffstat (limited to 'addons/website_mail/models')
-rw-r--r--addons/website_mail/models/__init__.py3
-rw-r--r--addons/website_mail/models/mail_message.py81
-rw-r--r--addons/website_mail/models/mail_thread.py18
-rw-r--r--addons/website_mail/models/update.py12
4 files changed, 53 insertions, 61 deletions
diff --git a/addons/website_mail/models/__init__.py b/addons/website_mail/models/__init__.py
index 313de6700ec..fcf3edd02fe 100644
--- a/addons/website_mail/models/__init__.py
+++ b/addons/website_mail/models/__init__.py
@@ -1,3 +1,6 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
import mail_message
import mail_thread
import update
diff --git a/addons/website_mail/models/mail_message.py b/addons/website_mail/models/mail_message.py
index e43a6eca9c0..7d9ded76a9f 100644
--- a/addons/website_mail/models/mail_message.py
+++ b/addons/website_mail/models/mail_message.py
@@ -1,37 +1,18 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-from openerp import SUPERUSER_ID
-from openerp.tools import html2plaintext
-from openerp.tools.translate import _
-from openerp.osv import osv, fields, expression
-from openerp.exceptions import AccessError
+from odoo import api, fields, models, SUPERUSER_ID, _
+from odoo.osv import expression
+from odoo.tools import html2plaintext
+from odoo.exceptions import AccessError
-class MailMessage(osv.Model):
- _inherit = 'mail.message'
-
- def _get_description_short(self, cr, uid, ids, name, arg, context=None):
- res = dict.fromkeys(ids, False)
- for message in self.browse(cr, uid, ids, context=context):
- if message.subject:
- res[message.id] = message.subject
- else:
- plaintext_ct = '' if not message.body else html2plaintext(message.body)
- res[message.id] = plaintext_ct[:30] + '%s' % (' [...]' if len(plaintext_ct) >= 30 else '')
- return res
- _columns = {
- 'description': fields.function(
- _get_description_short, type='char',
- help='Message description: either the subject, or the beginning of the body'
- ),
- 'website_published': fields.boolean(
- 'Published', help="Visible on the website as a comment", copy=False,
- ),
- }
+class MailMessage(models.Model):
+ _inherit = 'mail.message'
- def default_get(self, cr, uid, fields_list, context=None):
- defaults = super(MailMessage, self).default_get(cr, uid, fields_list, context=context)
+ @api.model
+ def default_get(self, fields_list):
+ defaults = super(MailMessage, self).default_get(fields_list)
# Note: explicitly implemented in default_get() instead of _defaults,
# to avoid setting to True for all existing messages during upgrades.
@@ -42,30 +23,40 @@ class MailMessage(osv.Model):
return defaults
- def _search(self, cr, uid, args, offset=0, limit=None, order=None,
- context=None, count=False, access_rights_uid=None):
+ description = fields.Char(compute="_compute_description", help='Message description: either the subject, or the beginning of the body')
+ website_published = fields.Boolean(string='Published', help="Visible on the website as a comment", copy=False)
+
+ @api.multi
+ def _compute_description(self):
+ for message in self:
+ if message.subject:
+ message.description = message.subject
+ else:
+ plaintext_ct = '' if not message.body else html2plaintext(message.body)
+ message.description = plaintext_ct[:30] + '%s' % (' [...]' if len(plaintext_ct) >= 30 else '')
+
+ @api.model
+ def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
""" Override that adds specific access rights of mail.message, to restrict
messages to published messages for public users. """
- if uid != SUPERUSER_ID:
- group_ids = self.pool.get('res.users').browse(cr, uid, uid, context=context).groups_id
- group_user_id = self.pool.get("ir.model.data").get_object_reference(cr, uid, 'base', 'group_public')[1]
- if group_user_id in [group.id for group in group_ids]:
+ if self.env.uid != SUPERUSER_ID:
+ group_user = self.env.ref('base.group_public')
+ if group_user in self.env.user.groups_id:
args = expression.AND([[('website_published', '=', True)], list(args)])
- return super(MailMessage, self)._search(cr, uid, args, offset=offset, limit=limit, order=order,
- context=context, count=count, access_rights_uid=access_rights_uid)
+ return super(MailMessage, self)._search(args, offset=offset, limit=limit, order=order,
+ count=count, access_rights_uid=access_rights_uid)
- def check_access_rule(self, cr, uid, ids, operation, context=None):
+ @api.multi
+ def check_access_rule(self, operation):
""" Add Access rules of mail.message for non-employee user:
- read:
- raise if the type is comment and subtype NULL (internal note)
"""
- if uid != SUPERUSER_ID:
- group_ids = self.pool.get('res.users').browse(cr, uid, uid, context=context).groups_id
- group_user_id = self.pool.get("ir.model.data").get_object_reference(cr, uid, 'base', 'group_public')[1]
- if group_user_id in [group.id for group in group_ids]:
- cr.execute('SELECT id FROM "%s" WHERE website_published IS FALSE AND id = ANY (%%s)' % (self._table), (ids,))
- if cr.fetchall():
+ if self.env.uid != SUPERUSER_ID:
+ group_user = self.env.ref('base.group_public')
+ if group_user in self.env.user.groups_id:
+ self.env.cr.execute('SELECT id FROM "%s" WHERE website_published IS FALSE AND id = ANY (%%s)' % (self._table), (self.ids,))
+ if self.env.cr.fetchall():
raise AccessError(_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s)') % (self._description, operation))
- return super(MailMessage, self).check_access_rule(cr, uid, ids=ids, operation=operation, context=context)
-
+ return super(MailMessage, self).check_access_rule(operation=operation)
diff --git a/addons/website_mail/models/mail_thread.py b/addons/website_mail/models/mail_thread.py
index 34e05b18612..5c0ace6722d 100644
--- a/addons/website_mail/models/mail_thread.py
+++ b/addons/website_mail/models/mail_thread.py
@@ -1,19 +1,13 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-from openerp.osv import osv, fields
+from odoo import fields, models
+
# TODO for trunk, remove me
-class MailThread(osv.AbstractModel):
+class MailThread(models.AbstractModel):
_inherit = 'mail.thread'
- _columns = {
- 'website_message_ids': fields.one2many(
- 'mail.message', 'res_id',
- domain=lambda self: [
- '&', ('model', '=', self._name), ('message_type', '=', 'comment')
- ],
- string='Website Messages',
- help="Website communication history",
- ),
- }
+ website_message_ids = fields.One2many('mail.message', 'res_id',
+ domain=lambda self: ['&', ('model', '=', self._name), ('message_type', '=', 'comment')],
+ string='Website Messages', help="Website communication history")
diff --git a/addons/website_mail/models/update.py b/addons/website_mail/models/update.py
index 924d30027c1..5367cb7df93 100644
--- a/addons/website_mail/models/update.py
+++ b/addons/website_mail/models/update.py
@@ -1,10 +1,14 @@
# -*- coding: utf-8 -*-
-from openerp.models import AbstractModel
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
-class publisher_warranty_contract(AbstractModel):
+from odoo import api, models
+
+
+class PublisherWarrantyContract(models.AbstractModel):
_inherit = "publisher_warranty.contract"
- def _get_message(self, cr, uid):
- msg = super(publisher_warranty_contract, self)._get_message(cr, uid)
+ @api.model
+ def _get_message(self):
+ msg = super(PublisherWarrantyContract, self)._get_message()
msg['website'] = True
return msg