From c518b3720405727a8719599d89c767788fc618c4 Mon Sep 17 00:00:00 2001 From: Gervais Naoussi Date: Wed, 28 Oct 2015 10:55:22 -0400 Subject: [PATCH 01/11] document_page_approval migration from Odoo 8.0 to Odoo 9.0 --- document_page_approval/README.rst | 91 +++++++++++++ document_page_approval/__init__.py | 5 +- document_page_approval/__openerp__.py | 29 +--- .../data/email_template.xml | 6 +- document_page_approval/models/__init__.py | 22 +++ .../models/document_page_approval.py | 127 ++++++++++++++++++ .../document_page_history_workflow.py} | 114 ++-------------- .../security/document_page_security.xml | 4 +- document_page_approval/tests/__init__.py | 2 + .../tests/test_document_page_approval.py | 16 +++ .../document_page_approval.xml} | 4 +- .../document_page_approval.xml} | 4 +- 12 files changed, 291 insertions(+), 133 deletions(-) create mode 100644 document_page_approval/README.rst create mode 100644 document_page_approval/models/__init__.py create mode 100644 document_page_approval/models/document_page_approval.py rename document_page_approval/{document_page_approval.py => models/document_page_history_workflow.py} (64%) create mode 100644 document_page_approval/tests/__init__.py create mode 100644 document_page_approval/tests/test_document_page_approval.py rename document_page_approval/{document_page_view.xml => views/document_page_approval.xml} (99%) rename document_page_approval/{document_page_wkfl.xml => workflows/document_page_approval.xml} (98%) diff --git a/document_page_approval/README.rst b/document_page_approval/README.rst new file mode 100644 index 00000000..43c7541a --- /dev/null +++ b/document_page_approval/README.rst @@ -0,0 +1,91 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +======================== +Management System - Base +======================== + +This module adds a workflow to approve page modification and show the approved +version by default. + +Installation +============ + +Makes the document page approval available from where some users can approved the modifications +made by others users in documents that required approvement. + +Configuration +============= + +No configuration required + +Usage +===== + +To use this module, you need to: + +* Set a valid email address on the company settings. +* go to knowledge > Categories. +* Create a new page category and set an approver group. Make sure users + belonging to that group have valid email addresses. +* go to knowledge > Pages +* Create a new page and choose the previously created category. +* A notification is sent to the group with a link to the page history to + review. +* Depending on the review, the page history is approved or not. +* Users reading the page see the last approved version. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/118/9.0 + +Known issues / Roadmap +====================== + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback `here `_. + + +Credits +======= + +Contributors +------------ + +* Odoo SA +* Savoir-faire Linux +* Gervais Naoussi + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. + +Changelog +--------- + +v9.0.1.0.0 + +Here are the modification that have been done: + +* The module does no depends anymore on email_template but on mail module diff --git a/document_page_approval/__init__.py b/document_page_approval/__init__.py index d2b3bb9e..9856810f 100644 --- a/document_page_approval/__init__.py +++ b/document_page_approval/__init__.py @@ -1,4 +1,5 @@ -# -*- encoding: utf-8 -*- +"""Project initialisation.""" +# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution @@ -18,4 +19,4 @@ # along with this program. If not, see . # ############################################################################## -from . import document_page_approval +from . import models diff --git a/document_page_approval/__openerp__.py b/document_page_approval/__openerp__.py index 3715ab8e..edefbd08 100644 --- a/document_page_approval/__openerp__.py +++ b/document_page_approval/__openerp__.py @@ -1,4 +1,5 @@ -# -*- encoding: utf-8 -*- +"""Module's configuration.""" +# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution @@ -21,40 +22,24 @@ { 'name': 'Document Page Approval', - 'version': '8.0.1.0.0', + 'version': '9.0.1.0.0', "author": "Savoir-faire Linux,Odoo Community Association (OCA)", "website": "http://www.savoirfairelinux.com", "license": "AGPL-3", 'category': 'Knowledge Management', - 'description': """ -This module adds a workflow to approve page modification and show the approved -version by default. - -Scenario -======== - -* Set a valid email address on the company settings. -* Create a new page category and set an approver group. Make sure users - belonging to that group have valid email addresses. -* Create a new page and choose the previously created category. -* A notification is sent to the group with a link to the page history to - review. -* Depending on the review, the page history is approved or not. -* Users reading the page see the last approved version. - """, 'depends': [ 'knowledge', 'document_page', - 'email_template', + 'mail', ], 'data': [ 'data/email_template.xml', - 'document_page_wkfl.xml', - 'document_page_view.xml', + 'workflows/document_page_approval.xml', + 'views/document_page_approval.xml', 'security/document_page_security.xml', 'security/ir.model.access.csv', ], - 'installable': False, + 'installable': True, 'auto_install': False, 'images': [ 'images/category.png', diff --git a/document_page_approval/data/email_template.xml b/document_page_approval/data/email_template.xml index 00a9734a..b5fc8ad8 100644 --- a/document_page_approval/data/email_template.xml +++ b/document_page_approval/data/email_template.xml @@ -1,12 +1,12 @@ - + + model="mail.template"> Automated new draft need approval Notification Mail ${object.create_uid.company_id.email or 'noreply@localhost.com'} New version of "${object.page_id.name}" to approve @@ -28,4 +28,4 @@ Odoo

]]>
-
+ diff --git a/document_page_approval/models/__init__.py b/document_page_approval/models/__init__.py new file mode 100644 index 00000000..eed978f8 --- /dev/null +++ b/document_page_approval/models/__init__.py @@ -0,0 +1,22 @@ +"""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 new file mode 100644 index 00000000..8e40fda5 --- /dev/null +++ b/document_page_approval/models/document_page_approval.py @@ -0,0 +1,127 @@ +"""Model DocumentPageApproval.""" +# -*- 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 openerp import models, fields + + +class DocumentPageApproval(models.Model): + """Useful to know the state of a document.""" + + _inherit = 'document.page' + + def _get_display_content(self): + """Display the content of document.""" + for page in self: + content = "" + if page.type == "category": + content = self._get_page_index(page, link=False) + else: + history = self.env['document.page.history'] + if self.is_approval_required(page): + history_ids = history.search( + [ + ('page_id', '=', page.id), + ('state', '=', 'approved') + ], + limit=1, + order='create_date DESC' + ) + content = history_ids.content + else: + content = page.content + page.display_content = content + + def _get_approved_date(self): + """Return the approved date of a document.""" + for page in self: + approved_date = False + if self.is_approval_required(page): + history = self.env['document.page.history'] + history_ids = history.search( + [ + ('page_id', '=', page.id), + ('state', '=', 'approved') + ], + limit=1, + order='create_date DESC' + ) + approved_date = history_ids.approved_date + page.approved_date = approved_date + + def _get_approved_uid(self): + """Return the user's id of the approved user.""" + for page in self: + approved_uid = False + if self.is_approval_required(page): + history = self.env['document.page.history'] + history_ids = history.search( + [ + ('page_id', '=', page.id), + ('state', '=', 'approved') + ], + limit=1, + order='create_date DESC' + ) + approved_uid = history_ids.approved_uid.id + page.approved_uid = approved_uid + + def _is_parent_approval_required(self): + """Check if the document required approval base on his parrent.""" + for page in self: + page.is_parent_approval_required = self.is_approval_required(page) + + def is_approval_required(self, page): + """Check if a document required approval.""" + if page: + res = page.approval_required + res = res or self.is_approval_required(page.parent_id) + else: + res = False + return res + + display_content = fields.Text( + compute=_get_display_content, + string='Displayed Content' + ) + + approved_date = fields.Datetime( + compute=_get_approved_date, + string="Approved Date" + ) + + approved_uid = fields.Many2one( + 'res.users', + compute=_get_approved_uid, + string="Approved By", + ) + + approval_required = fields.Boolean("Require approval") + + is_parent_approval_required = fields.Boolean( + compute=_is_parent_approval_required, + string="parent approval" + ) + + approver_gid = fields.Many2one( + "res.groups", + "Approver group" + ) diff --git a/document_page_approval/document_page_approval.py b/document_page_approval/models/document_page_history_workflow.py similarity index 64% rename from document_page_approval/document_page_approval.py rename to document_page_approval/models/document_page_history_workflow.py index 8f11e5f7..b566def0 100644 --- a/document_page_approval/document_page_approval.py +++ b/document_page_approval/models/document_page_history_workflow.py @@ -1,4 +1,5 @@ -# -*- encoding: utf-8 -*- +"""DocumentPageHistoryWorkflow model.""" +# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution @@ -25,10 +26,13 @@ from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT from openerp import models, fields, SUPERUSER_ID -class document_page_history_wkfl(models.Model): +class DocumentPageHistoryWorkflow(models.Model): + """Useful to manage edition's workflow on a document.""" + _inherit = 'document.page.history' def page_approval_draft(self, cr, uid, ids, context=None): + """Set a document state as draft and notified the reviewers.""" self.write(cr, uid, ids, {'state': 'draft'}) template_id = self.pool.get('ir.model.data').get_object_reference( cr, uid, @@ -36,7 +40,7 @@ class document_page_history_wkfl(models.Model): 'email_template_new_draft_need_approval')[1] for page in self.browse(cr, uid, ids, context=context): if page.is_parent_approval_required: - self.pool.get('email.template').send_mail( + self.pool.get('mail.template').send_mail( cr, uid, template_id, @@ -46,6 +50,7 @@ class document_page_history_wkfl(models.Model): return True def page_approval_approved(self, cr, uid, ids, context=None): + """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, { @@ -70,6 +75,7 @@ class document_page_history_wkfl(models.Model): return True def _can_user_approve_page(self): + """Check if a user cas approve the page.""" user = self.env.user for page in self: page.can_user_approve_page = page.can_user_approve_this_page( @@ -78,6 +84,7 @@ class document_page_history_wkfl(models.Model): ) def can_user_approve_this_page(self, page, user): + """Check if a user can approved the page.""" if page: res = page.approver_gid in user.groups_id res = res or self.can_user_approve_this_page(page.parent_id, user) @@ -86,12 +93,14 @@ class document_page_history_wkfl(models.Model): return res def get_approvers_guids(self): + """Return the approvers group.""" res = {} for page in self: res[page.id] = self.get_approvers_guids_for_page(page.page_id) return res def get_approvers_guids_for_page(self, page): + """Return the approvers group for a page.""" if page: if page.approver_gid: res = [page.approver_gid.id] @@ -104,6 +113,7 @@ class document_page_history_wkfl(models.Model): return res def _get_approvers_email(self): + """Get the approvers email.""" for page in self: emails = '' guids = self.get_approvers_guids() @@ -127,6 +137,7 @@ class document_page_history_wkfl(models.Model): page.get_approvers_email = emails[:-1] def _get_page_url(self): + """Get the page url.""" for page in self: base_url = self.env['ir.config_parameter'].get_param( 'web.base.url', @@ -175,100 +186,3 @@ class document_page_history_wkfl(models.Model): string="URL", store=False ) - - -class document_page_approval(models.Model): - _inherit = 'document.page' - - def _get_display_content(self): - for page in self: - content = "" - if page.type == "category": - content = self._get_page_index(page, link=False) - else: - history = self.env['document.page.history'] - if self.is_approval_required(page): - history_ids = history.search( - [ - ('page_id', '=', page.id), - ('state', '=', 'approved') - ], - limit=1, - order='create_date DESC' - ) - content = history_ids.content - else: - content = page.content - page.display_content = content - - def _get_approved_date(self): - for page in self: - approved_date = False - if self.is_approval_required(page): - history = self.env['document.page.history'] - history_ids = history.search( - [ - ('page_id', '=', page.id), - ('state', '=', 'approved') - ], - limit=1, - order='create_date DESC' - ) - approved_date = history_ids.approved_date - page.approved_date = approved_date - - def _get_approved_uid(self): - for page in self: - approved_uid = False - if self.is_approval_required(page): - history = self.env['document.page.history'] - history_ids = history.search( - [ - ('page_id', '=', page.id), - ('state', '=', 'approved') - ], - limit=1, - order='create_date DESC' - ) - approved_uid = history_ids.approved_uid.id - page.approved_uid = approved_uid - - def _is_parent_approval_required(self): - for page in self: - page.is_parent_approval_required = self.is_approval_required(page) - - def is_approval_required(self, page): - if page: - res = page.approval_required - res = res or self.is_approval_required(page.parent_id) - else: - res = False - return res - - display_content = fields.Text( - compute=_get_display_content, - string='Displayed Content' - ) - - approved_date = fields.Datetime( - compute=_get_approved_date, - string="Approved Date" - ) - - approved_uid = fields.Many2one( - 'res.users', - compute=_get_approved_uid, - string="Approved By", - ) - - approval_required = fields.Boolean("Require approval") - - is_parent_approval_required = fields.Boolean( - compute=_is_parent_approval_required, - string="parent approval" - ) - - approver_gid = fields.Many2one( - "res.groups", - "Approver group" - ) diff --git a/document_page_approval/security/document_page_security.xml b/document_page_approval/security/document_page_security.xml index 7192d3f8..0e5bfd66 100644 --- a/document_page_approval/security/document_page_security.xml +++ b/document_page_approval/security/document_page_security.xml @@ -1,9 +1,9 @@ - + Document approver - + diff --git a/document_page_approval/tests/__init__.py b/document_page_approval/tests/__init__.py new file mode 100644 index 00000000..7efd37ec --- /dev/null +++ b/document_page_approval/tests/__init__.py @@ -0,0 +1,2 @@ +"""Module test initialisation.""" +# -*- coding: utf-8 -*- diff --git a/document_page_approval/tests/test_document_page_approval.py b/document_page_approval/tests/test_document_page_approval.py new file mode 100644 index 00000000..2310fe3a --- /dev/null +++ b/document_page_approval/tests/test_document_page_approval.py @@ -0,0 +1,16 @@ +"""DocumentPageApproval test.""" +# -*- coding: utf-8 -*- +from openerp.test.common import TransactionCase + + +class TestDocumentPageApproval(TransactionCase): + """Test document page approval model.""" + + def setUp(self): + """Test setUp.""" + super() + pass + + def __init__(self, arg): + """Test initialisation.""" + pass diff --git a/document_page_approval/document_page_view.xml b/document_page_approval/views/document_page_approval.xml similarity index 99% rename from document_page_approval/document_page_view.xml rename to document_page_approval/views/document_page_approval.xml index e12885fa..47446916 100644 --- a/document_page_approval/document_page_view.xml +++ b/document_page_approval/views/document_page_approval.xml @@ -1,5 +1,5 @@ - + document.page.history.form @@ -90,4 +90,4 @@ - + diff --git a/document_page_approval/document_page_wkfl.xml b/document_page_approval/workflows/document_page_approval.xml similarity index 98% rename from document_page_approval/document_page_wkfl.xml rename to document_page_approval/workflows/document_page_approval.xml index 7dc85019..1854e6f3 100644 --- a/document_page_approval/document_page_wkfl.xml +++ b/document_page_approval/workflows/document_page_approval.xml @@ -1,5 +1,5 @@ - + @@ -40,4 +40,4 @@ - + From 878f2d686ce158e8192be1126c40f351f1bbdbbb Mon Sep 17 00:00:00 2001 From: Gervais Naoussi Date: Thu, 10 Dec 2015 08:15:14 +0100 Subject: [PATCH 02/11] Lint error corrected --- document_page_approval/README.rst | 7 ++----- document_page_approval/__openerp__.py | 1 - 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/document_page_approval/README.rst b/document_page_approval/README.rst index 43c7541a..d2c33709 100644 --- a/document_page_approval/README.rst +++ b/document_page_approval/README.rst @@ -3,7 +3,7 @@ :alt: License: AGPL-3 ======================== -Management System - Base +Document Page Approval ======================== This module adds a workflow to approve page modification and show the approved @@ -50,10 +50,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed feedback `here `_. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback `here `_. Credits diff --git a/document_page_approval/__openerp__.py b/document_page_approval/__openerp__.py index edefbd08..1e95feb3 100644 --- a/document_page_approval/__openerp__.py +++ b/document_page_approval/__openerp__.py @@ -1,4 +1,3 @@ -"""Module's configuration.""" # -*- coding: utf-8 -*- ############################################################################## # From 432d141ce06e57c3a7355a6df4721927ac3f8c47 Mon Sep 17 00:00:00 2001 From: Gervais Naoussi Date: Thu, 10 Dec 2015 10:21:44 +0100 Subject: [PATCH 03/11] test improved --- document_page_approval/tests/__init__.py | 1 + .../tests/test_document_page_approval.py | 37 ++++++++++++++----- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/document_page_approval/tests/__init__.py b/document_page_approval/tests/__init__.py index 7efd37ec..4d55c4d9 100644 --- a/document_page_approval/tests/__init__.py +++ b/document_page_approval/tests/__init__.py @@ -1,2 +1,3 @@ """Module test initialisation.""" # -*- coding: utf-8 -*- +from . import test_document_page_approval diff --git a/document_page_approval/tests/test_document_page_approval.py b/document_page_approval/tests/test_document_page_approval.py index 2310fe3a..3181815c 100644 --- a/document_page_approval/tests/test_document_page_approval.py +++ b/document_page_approval/tests/test_document_page_approval.py @@ -1,16 +1,35 @@ """DocumentPageApproval test.""" # -*- coding: utf-8 -*- -from openerp.test.common import TransactionCase +from openerp.tests import common -class TestDocumentPageApproval(TransactionCase): +class TestDocumentPageApproval(common.TransactionCase): """Test document page approval model.""" - def setUp(self): - """Test setUp.""" - super() - pass + def test_get_display_content(self): + """Test page display content.""" + # Check content of a category + category = self.env['document.page'].search( + [('name', '=', 'OpenERP Features')]) - def __init__(self, arg): - """Test initialisation.""" - pass + self.assertIsNotNone(category.display_content, 'a category') + + # Check content of a page + pages = self.env['document.page'].search( + [('parent_id', '=', category.id)]) + page = pages[0] + self.assertIsNotNone(page.display_content, 'Page content') + + # Check if approval is required + self.assertFalse(page.is_approval_required(page)) + + # Check content of an approval page + page.approval_required = True + + self.assertIsNotNone(page.display_content, 'Page content') + + # Check if approval is required + self.assertTrue(page.is_approval_required(page)) + + # Check if parent approval is required + self.assertFalse(page.is_parent_approval_required) From 07dd7898bb274b06df7cd977ef8220b8ac1a150e Mon Sep 17 00:00:00 2001 From: Gervais Naoussi Date: Thu, 10 Dec 2015 16:14:58 +0100 Subject: [PATCH 04/11] lint error corrected in test file --- .../tests/test_document_page_approval.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/document_page_approval/tests/test_document_page_approval.py b/document_page_approval/tests/test_document_page_approval.py index 3181815c..c430f5b9 100644 --- a/document_page_approval/tests/test_document_page_approval.py +++ b/document_page_approval/tests/test_document_page_approval.py @@ -9,14 +9,16 @@ class TestDocumentPageApproval(common.TransactionCase): def test_get_display_content(self): """Test page display content.""" # Check content of a category - category = self.env['document.page'].search( - [('name', '=', 'OpenERP Features')]) + category = self.env['document.page'].search([ + ('name', '=', 'OpenERP Features') + ]) self.assertIsNotNone(category.display_content, 'a category') # Check content of a page - pages = self.env['document.page'].search( - [('parent_id', '=', category.id)]) + pages = self.env['document.page'].search([ + ('parent_id', '=', category.id) + ]) page = pages[0] self.assertIsNotNone(page.display_content, 'Page content') @@ -32,4 +34,4 @@ class TestDocumentPageApproval(common.TransactionCase): self.assertTrue(page.is_approval_required(page)) # Check if parent approval is required - self.assertFalse(page.is_parent_approval_required) + self.assertTrue(page.is_parent_approval_required) From 33c70a5c2b3c3bc0f43ebc69b610c2e6646b8f83 Mon Sep 17 00:00:00 2001 From: Gervais Naoussi Date: Thu, 10 Dec 2015 17:25:26 +0100 Subject: [PATCH 05/11] readme corrected --- document_page_approval/README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/document_page_approval/README.rst b/document_page_approval/README.rst index d2c33709..affff9ce 100644 --- a/document_page_approval/README.rst +++ b/document_page_approval/README.rst @@ -2,9 +2,9 @@ :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 -======================== +====================== Document Page Approval -======================== +====================== This module adds a workflow to approve page modification and show the approved version by default. From 9182b4e3071d0c4e0c7398a77120013c43e2aec2 Mon Sep 17 00:00:00 2001 From: Gervais Naoussi Date: Wed, 16 Dec 2015 12:29:56 +0100 Subject: [PATCH 06/11] test improved --- document_page_approval/tests/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/document_page_approval/tests/__init__.py b/document_page_approval/tests/__init__.py index 4d55c4d9..5797c27d 100644 --- a/document_page_approval/tests/__init__.py +++ b/document_page_approval/tests/__init__.py @@ -1,3 +1,3 @@ """Module test initialisation.""" # -*- coding: utf-8 -*- -from . import test_document_page_approval +from . import test_document_page_approval, test_document_page_history_workflow From d3e7a11b7cde24362c52d4db6611493533b84b8c Mon Sep 17 00:00:00 2001 From: Gervais Naoussi Date: Wed, 16 Dec 2015 12:40:02 +0100 Subject: [PATCH 07/11] test of document page history workflow added --- .../tests/test_document_page_approval.py | 6 +- .../test_document_page_history_workflow.py | 59 +++++++++++++++++++ 2 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 document_page_approval/tests/test_document_page_history_workflow.py diff --git a/document_page_approval/tests/test_document_page_approval.py b/document_page_approval/tests/test_document_page_approval.py index c430f5b9..01795c10 100644 --- a/document_page_approval/tests/test_document_page_approval.py +++ b/document_page_approval/tests/test_document_page_approval.py @@ -9,11 +9,9 @@ class TestDocumentPageApproval(common.TransactionCase): def test_get_display_content(self): """Test page display content.""" # Check content of a category - category = self.env['document.page'].search([ - ('name', '=', 'OpenERP Features') - ]) + category = self.ref('document_page.demo_category1') - self.assertIsNotNone(category.display_content, 'a category') + self.assertIsNotNone(category.display_content) # Check content of a page pages = self.env['document.page'].search([ diff --git a/document_page_approval/tests/test_document_page_history_workflow.py b/document_page_approval/tests/test_document_page_history_workflow.py new file mode 100644 index 00000000..e56a518b --- /dev/null +++ b/document_page_approval/tests/test_document_page_history_workflow.py @@ -0,0 +1,59 @@ +"""DocumentPageApproval test.""" +# -*- coding: utf-8 -*- +from openerp.tests import common +# Import logger +import logging + +# Get the logger +_logger = logging.getLogger(__name__) + + +class TestDocumentPageHistoryWorkflow(common.TransactionCase): + """Test document page history workflow.""" + + def test_can_user_approve_this_page(self): + """Test if a user can approve this page.""" + user = self.env.user + category = self.env.ref('document_page.demo_category1') + category.approval_required = True + category.approver_uid = user + + pages = self.env['document.page.history'].search([ + ('page_id', '=', category.id) + ]) + page = pages[0] + + self.assertTrue(page.can_user_approve) + + def test_get_approvers_guids(self): + """Get approver guids.""" + category = self.env.ref('document_page.demo_category1') + category.approval_required = True + pages = self.env['document.page.history'].search([ + ('page_id', '=', category.id) + ]) + page = pages[0] + approvers_guid = page.get_approvers_guids() + self.assertTrue(len(approvers_guid) > 0) + + def test_get_approvers_email(self): + """Get approver email.""" + category = self.env.ref('document_page.demo_category1') + category.approval_required = True + pages = self.env['document.page.history'].search([ + ('page_id', '=', category.id) + ]) + page = pages[0] + _logger.info("Email: " + str(page.get_approvers_email)) + self.assertIsNotNone(page.get_approvers_email) + + def test_get_page_url(self): + """Test if page url exist.""" + category = self.env.ref('document_page.demo_category1') + category.approval_required = True + pages = self.env['document.page.history'].search([ + ('page_id', '=', category.id) + ]) + page = pages[0] + _logger.info("Page: "+str(page.get_page_url)) + self.assertIsNotNone(page.get_page_url) From 4ef00a8b9a3c6147d0a48628372d4824aa2da6a0 Mon Sep 17 00:00:00 2001 From: Gervais Naoussi Date: Wed, 16 Dec 2015 12:47:51 +0100 Subject: [PATCH 08/11] CI error corrected --- document_page_approval/tests/test_document_page_approval.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/document_page_approval/tests/test_document_page_approval.py b/document_page_approval/tests/test_document_page_approval.py index 01795c10..c430f5b9 100644 --- a/document_page_approval/tests/test_document_page_approval.py +++ b/document_page_approval/tests/test_document_page_approval.py @@ -9,9 +9,11 @@ class TestDocumentPageApproval(common.TransactionCase): def test_get_display_content(self): """Test page display content.""" # Check content of a category - category = self.ref('document_page.demo_category1') + category = self.env['document.page'].search([ + ('name', '=', 'OpenERP Features') + ]) - self.assertIsNotNone(category.display_content) + self.assertIsNotNone(category.display_content, 'a category') # Check content of a page pages = self.env['document.page'].search([ From 14a88d95548e3eca12dc92f2463843eeb7f7367e Mon Sep 17 00:00:00 2001 From: Gervais Naoussi Date: Wed, 16 Dec 2015 13:04:50 +0100 Subject: [PATCH 09/11] dreipst comment --- document_page_approval/__init__.py | 1 - document_page_approval/models/document_page_approval.py | 1 - document_page_approval/models/document_page_history_workflow.py | 1 - 3 files changed, 3 deletions(-) diff --git a/document_page_approval/__init__.py b/document_page_approval/__init__.py index 9856810f..7f626589 100644 --- a/document_page_approval/__init__.py +++ b/document_page_approval/__init__.py @@ -1,4 +1,3 @@ -"""Project initialisation.""" # -*- coding: utf-8 -*- ############################################################################## # diff --git a/document_page_approval/models/document_page_approval.py b/document_page_approval/models/document_page_approval.py index 8e40fda5..c76c7e64 100644 --- a/document_page_approval/models/document_page_approval.py +++ b/document_page_approval/models/document_page_approval.py @@ -1,4 +1,3 @@ -"""Model DocumentPageApproval.""" # -*- coding: utf-8 -*- ############################################################################## # diff --git a/document_page_approval/models/document_page_history_workflow.py b/document_page_approval/models/document_page_history_workflow.py index b566def0..6aa5d7eb 100644 --- a/document_page_approval/models/document_page_history_workflow.py +++ b/document_page_approval/models/document_page_history_workflow.py @@ -1,4 +1,3 @@ -"""DocumentPageHistoryWorkflow model.""" # -*- coding: utf-8 -*- ############################################################################## # From 8626a02aef6ae18618f45daaab2c2610ecc199e7 Mon Sep 17 00:00:00 2001 From: Gervais Naoussi Date: Mon, 18 Jan 2016 02:05:11 +0100 Subject: [PATCH 10/11] 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 - - - From 84d81949d7498a85d612a4314629e6ee0af44fbe Mon Sep 17 00:00:00 2001 From: Gervais Naoussi Date: Wed, 20 Jan 2016 12:07:18 +0100 Subject: [PATCH 11/11] code totally migrate to odoo 9.0 api --- document_page_approval/models/__init__.py | 1 - .../models/document_page_approval.py | 1 + .../models/document_page_history_workflow.py | 30 ++++++++----------- document_page_approval/tests/__init__.py | 1 - 4 files changed, 14 insertions(+), 19 deletions(-) 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