From 8626a02aef6ae18618f45daaab2c2610ecc199e7 Mon Sep 17 00:00:00 2001 From: Gervais Naoussi Date: Mon, 18 Jan 2016 02:05:11 +0100 Subject: [PATCH] Migration to new api improved in model's file and data tag remove in xml file --- document_page_approval/models/__init__.py | 19 -------------- .../models/document_page_approval.py | 5 +++- .../models/document_page_history_workflow.py | 25 +++++++++---------- .../tests/test_document_page_approval.py | 1 - .../test_document_page_history_workflow.py | 1 - .../views/document_page_approval.xml | 2 -- .../workflows/document_page_approval.xml | 5 ---- 7 files changed, 16 insertions(+), 42 deletions(-) diff --git a/document_page_approval/models/__init__.py b/document_page_approval/models/__init__.py index eed978f8..ab714792 100644 --- a/document_page_approval/models/__init__.py +++ b/document_page_approval/models/__init__.py @@ -1,22 +1,3 @@ """Data models initialisation.""" # -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2013 Savoir-faire Linux (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## 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 c76c7e64..21b6913a 100644 --- a/document_page_approval/models/document_page_approval.py +++ b/document_page_approval/models/document_page_approval.py @@ -19,7 +19,7 @@ # ############################################################################## -from openerp import models, fields +from openerp import models, fields, api class DocumentPageApproval(models.Model): @@ -27,6 +27,7 @@ class DocumentPageApproval(models.Model): _inherit = 'document.page' + @api.multi def _get_display_content(self): """Display the content of document.""" for page in self: @@ -49,6 +50,7 @@ class DocumentPageApproval(models.Model): content = page.content page.display_content = content + @api.multi def _get_approved_date(self): """Return the approved date of a document.""" for page in self: @@ -66,6 +68,7 @@ class DocumentPageApproval(models.Model): approved_date = history_ids.approved_date page.approved_date = approved_date + @api.multi def _get_approved_uid(self): """Return the user's id of the approved user.""" 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 6aa5d7eb..5e7c5357 100644 --- a/document_page_approval/models/document_page_history_workflow.py +++ b/document_page_approval/models/document_page_history_workflow.py @@ -30,40 +30,39 @@ class DocumentPageHistoryWorkflow(models.Model): _inherit = 'document.page.history' - def page_approval_draft(self, cr, uid, ids, context=None): + def page_approval_draft(self): """Set a document state as draft and notified the reviewers.""" - self.write(cr, uid, ids, {'state': 'draft'}) + self.write({'state': 'draft'}) template_id = self.pool.get('ir.model.data').get_object_reference( - cr, uid, + self.env.cr, self.env.uid, 'document_page_approval', 'email_template_new_draft_need_approval')[1] - for page in self.browse(cr, uid, ids, context=context): + for page in self: if page.is_parent_approval_required: self.pool.get('mail.template').send_mail( - cr, - uid, + self.env.cr, self.env.uid, template_id, page.id, force_send=True ) return True - def page_approval_approved(self, cr, uid, ids, context=None): + 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') - self.write(cr, uid, ids, { + self.write({ 'state': 'approved', 'approved_date': datetime.now().strftime( DEFAULT_SERVER_DATETIME_FORMAT), - 'approved_uid': uid - }, context=context) + 'approved_uid': self.env.uid + }) # Notify followers a new version is available - for page_history in self.browse(cr, uid, ids, context=context): + for page_history in self: subtype_id = model_data_obj.get_object_reference( - cr, SUPERUSER_ID, 'mail', 'mt_comment')[1] + self.env.cr, SUPERUSER_ID, 'mail', 'mt_comment')[1] message_obj.create( - cr, uid, + self.env.cr, self.env.uid, {'res_id': page_history.page_id.id, 'model': 'document.page', 'subtype_id': subtype_id, diff --git a/document_page_approval/tests/test_document_page_approval.py b/document_page_approval/tests/test_document_page_approval.py index c430f5b9..0ac7232d 100644 --- a/document_page_approval/tests/test_document_page_approval.py +++ b/document_page_approval/tests/test_document_page_approval.py @@ -1,4 +1,3 @@ -"""DocumentPageApproval test.""" # -*- coding: utf-8 -*- from openerp.tests import common diff --git a/document_page_approval/tests/test_document_page_history_workflow.py b/document_page_approval/tests/test_document_page_history_workflow.py index e56a518b..bca965d3 100644 --- a/document_page_approval/tests/test_document_page_history_workflow.py +++ b/document_page_approval/tests/test_document_page_history_workflow.py @@ -1,4 +1,3 @@ -"""DocumentPageApproval test.""" # -*- coding: utf-8 -*- from openerp.tests import common # Import logger diff --git a/document_page_approval/views/document_page_approval.xml b/document_page_approval/views/document_page_approval.xml index 47446916..6b0e5c91 100644 --- a/document_page_approval/views/document_page_approval.xml +++ b/document_page_approval/views/document_page_approval.xml @@ -1,6 +1,5 @@ - document.page.history.form document.page.history @@ -89,5 +88,4 @@ - diff --git a/document_page_approval/workflows/document_page_approval.xml b/document_page_approval/workflows/document_page_approval.xml index 1854e6f3..ea8a254b 100644 --- a/document_page_approval/workflows/document_page_approval.xml +++ b/document_page_approval/workflows/document_page_approval.xml @@ -1,7 +1,5 @@ - - document.page.history.aproval.wkf document.page.history @@ -37,7 +35,4 @@ edit - - -