diff --git a/document_page_approval/models/__init__.py b/document_page_approval/models/__init__.py index ab714792..91075fe8 100644 --- a/document_page_approval/models/__init__.py +++ b/document_page_approval/models/__init__.py @@ -1,3 +1,2 @@ -"""Data models initialisation.""" # -*- coding: utf-8 -*- from . import document_page_approval, document_page_history_workflow diff --git a/document_page_approval/models/document_page_approval.py b/document_page_approval/models/document_page_approval.py index 21b6913a..278f5227 100644 --- a/document_page_approval/models/document_page_approval.py +++ b/document_page_approval/models/document_page_approval.py @@ -86,6 +86,7 @@ class DocumentPageApproval(models.Model): approved_uid = history_ids.approved_uid.id page.approved_uid = approved_uid + @api.multi def _is_parent_approval_required(self): """Check if the document required approval base on his parrent.""" for page in self: diff --git a/document_page_approval/models/document_page_history_workflow.py b/document_page_approval/models/document_page_history_workflow.py index 5e7c5357..2eeb7e91 100644 --- a/document_page_approval/models/document_page_history_workflow.py +++ b/document_page_approval/models/document_page_history_workflow.py @@ -22,7 +22,7 @@ from datetime import datetime from openerp.tools.translate import _ from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT -from openerp import models, fields, SUPERUSER_ID +from openerp import models, fields, api class DocumentPageHistoryWorkflow(models.Model): @@ -30,27 +30,21 @@ class DocumentPageHistoryWorkflow(models.Model): _inherit = 'document.page.history' + @api.multi def page_approval_draft(self): """Set a document state as draft and notified the reviewers.""" self.write({'state': 'draft'}) - template_id = self.pool.get('ir.model.data').get_object_reference( - self.env.cr, self.env.uid, - 'document_page_approval', - 'email_template_new_draft_need_approval')[1] + template = self.env.ref( + 'document_page_approval.email_template_new_draft_need_approval') for page in self: if page.is_parent_approval_required: - self.pool.get('mail.template').send_mail( - self.env.cr, self.env.uid, - template_id, - page.id, - force_send=True - ) + template.send_mail(page.id, force_send=True) return True + @api.multi def page_approval_approved(self): """Set a document state as approve.""" - model_data_obj = self.pool.get('ir.model.data') - message_obj = self.pool.get('mail.message') + message_obj = self.env['mail.message'] self.write({ 'state': 'approved', 'approved_date': datetime.now().strftime( @@ -59,19 +53,18 @@ class DocumentPageHistoryWorkflow(models.Model): }) # Notify followers a new version is available for page_history in self: - subtype_id = model_data_obj.get_object_reference( - self.env.cr, SUPERUSER_ID, 'mail', 'mt_comment')[1] + subtype = self.env.ref('mail.mt_comment') message_obj.create( - self.env.cr, self.env.uid, {'res_id': page_history.page_id.id, 'model': 'document.page', - 'subtype_id': subtype_id, + 'subtype_id': subtype.id, 'body': _('New version of the document %s' ' approved.') % page_history.page_id.name } ) return True + @api.multi def _can_user_approve_page(self): """Check if a user cas approve the page.""" user = self.env.user @@ -90,6 +83,7 @@ class DocumentPageHistoryWorkflow(models.Model): res = False return res + @api.multi def get_approvers_guids(self): """Return the approvers group.""" res = {} @@ -110,6 +104,7 @@ class DocumentPageHistoryWorkflow(models.Model): return res + @api.multi def _get_approvers_email(self): """Get the approvers email.""" for page in self: @@ -134,6 +129,7 @@ class DocumentPageHistoryWorkflow(models.Model): page.get_approvers_email = emails[:-1] + @api.multi def _get_page_url(self): """Get the page url.""" for page in self: diff --git a/document_page_approval/tests/__init__.py b/document_page_approval/tests/__init__.py index 5797c27d..2413da81 100644 --- a/document_page_approval/tests/__init__.py +++ b/document_page_approval/tests/__init__.py @@ -1,3 +1,2 @@ -"""Module test initialisation.""" # -*- coding: utf-8 -*- from . import test_document_page_approval, test_document_page_history_workflow