diff --git a/document_page_approval/README.rst b/document_page_approval/README.rst index 7f3d78af..21b0cc54 100644 --- a/document_page_approval/README.rst +++ b/document_page_approval/README.rst @@ -34,7 +34,7 @@ To use this module, you need to: .. 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/10.0 + :target: https://runbot.odoo-community.org/runbot/118/11.0 Known issues / Roadmap ====================== diff --git a/document_page_approval/__init__.py b/document_page_approval/__init__.py index a9f5c87d..f94cf31a 100644 --- a/document_page_approval/__init__.py +++ b/document_page_approval/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (C) 2013 Savoir-faire Linux (). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/document_page_approval/__manifest__.py b/document_page_approval/__manifest__.py index a2403bbb..61a39bfc 100644 --- a/document_page_approval/__manifest__.py +++ b/document_page_approval/__manifest__.py @@ -1,10 +1,9 @@ -# -*- coding: utf-8 -*- # Copyright (C) 2013 Savoir-faire Linux (). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Document Page Approval', - 'version': '10.0.2.0.0', + 'version': '11.0.1.0.0', "author": "Savoir-faire Linux, Odoo Community Association (OCA)", "website": "http://www.savoirfairelinux.com", "license": "AGPL-3", @@ -15,7 +14,6 @@ ], 'data': [ 'data/email_template.xml', - 'workflows/document_page_approval.xml', 'views/document_page_approval.xml', 'security/document_page_security.xml', 'security/ir.model.access.csv', @@ -27,4 +25,5 @@ ], 'post_init_hook': 'post_init_hook', 'uninstall_hook': 'uninstall_hook', + 'installable': True, } diff --git a/document_page_approval/hooks.py b/document_page_approval/hooks.py index 4e02a759..212e6583 100644 --- a/document_page_approval/hooks.py +++ b/document_page_approval/hooks.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2018 Ivan Todorovich () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/document_page_approval/migrations/10.0.2.0.0/post-migration.py b/document_page_approval/migrations/10.0.2.0.0/post-migration.py deleted file mode 100644 index b9fd8954..00000000 --- a/document_page_approval/migrations/10.0.2.0.0/post-migration.py +++ /dev/null @@ -1,14 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2018 Ivan Todorovich -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). - - -def migrate(cr, version): # pragma: no cover - # Set all pre-existing pages history to approved - cr.execute(""" - UPDATE document_page_history - SET state='approved', - approved_uid=create_uid, - approved_date=create_date - WHERE state IS NULL - """) diff --git a/document_page_approval/models/__init__.py b/document_page_approval/models/__init__.py index 91075fe8..e1b9d5b5 100644 --- a/document_page_approval/models/__init__.py +++ b/document_page_approval/models/__init__.py @@ -1,2 +1 @@ -# -*- 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 5ff46dfe..370b4407 100644 --- a/document_page_approval/models/document_page_approval.py +++ b/document_page_approval/models/document_page_approval.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (C) 2013 Savoir-faire Linux (). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -123,7 +122,7 @@ class DocumentPageApproval(models.Model): @api.multi def _create_history(self, vals): res = super(DocumentPageApproval, self)._create_history(vals) - res.signal_workflow('document_page_auto_confirm') + res.document_page_auto_confirm() @api.multi def action_changes_pending_approval(self): diff --git a/document_page_approval/models/document_page_history_workflow.py b/document_page_approval/models/document_page_history_workflow.py index a745ea58..3944afec 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 @@ -# -*- coding: utf-8 -*- # Copyright (C) 2013 Savoir-faire Linux (). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -6,6 +5,7 @@ from datetime import datetime from odoo.tools.translate import _ from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT from odoo import api, fields, models +from odoo.exceptions import UserError class DocumentPageHistoryWorkflow(models.Model): @@ -21,6 +21,7 @@ class DocumentPageHistoryWorkflow(models.Model): ('cancelled', 'Cancelled')], 'Status', readonly=True, + default='draft' ) approved_date = fields.Datetime( @@ -42,7 +43,7 @@ class DocumentPageHistoryWorkflow(models.Model): ) am_i_approver = fields.Boolean( - related='page_id.am_i_approver' + compute='_compute_am_i_approver' ) page_url = fields.Text( @@ -53,8 +54,27 @@ class DocumentPageHistoryWorkflow(models.Model): @api.multi def page_approval_draft(self): """Set a change request as draft""" + if self.filtered(lambda r: r.state not in [ + 'cancelled', 'approved']): + raise UserError(_("It's not cancelled or approved")) + if self.filtered(lambda r: + r.state == 'approved' and not self.am_i_approver): + raise UserError(_("You are not an appover to reset to draft")) self.write({'state': 'draft'}) + @api.multi + def document_page_auto_confirm(self): + """Automatic Transitions for change requests created directly from + documents + """ + if self.filtered(lambda r: r.state != 'draft'): + raise UserError(_("It's not in draft state")) + to_approve = self.filtered(lambda r: r.is_approval_required) + to_approve.write({'state': 'to approve'}) + approved = (self - to_approve) + approved.write({'state': 'approved'}) + approved.mapped('page_id')._compute_history_head() + @api.multi def page_approval_to_approve(self): """Set a change request as to approve""" @@ -117,11 +137,18 @@ class DocumentPageHistoryWorkflow(models.Model): for rec in self: rec.am_i_owner = (rec.create_uid == self.env.user) + @api.multi + def _compute_am_i_approver(self): + """check if current user is a approver""" + for rec in self: + rec.am_i_approver = rec.page_id.can_user_approve_this_page( + self.env.user) + @api.multi def _compute_page_url(self): """Compute the page url.""" for page in self: - base_url = self.env['ir.config_parameter'].get_param( + base_url = self.env['ir.config_parameter'].sudo().get_param( 'web.base.url', default='http://localhost:8069' ) diff --git a/document_page_approval/tests/__init__.py b/document_page_approval/tests/__init__.py index 30782b8b..6f4fbfc9 100644 --- a/document_page_approval/tests/__init__.py +++ b/document_page_approval/tests/__init__.py @@ -1,2 +1 @@ -# -*- 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 5e4f89b5..8fcd73e9 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 @@ -# -*- coding: utf-8 -*- from odoo.tests import common @@ -23,7 +22,7 @@ class TestDocumentPageApproval(common.TransactionCase): self.page2 = self.page_obj.create({ 'name': 'This page requires approval', 'parent_id': self.category2.id, - 'content': 'This content will require approval' + 'content': 'This content will require approval', }) def test_approval_required(self): @@ -48,7 +47,7 @@ class TestDocumentPageApproval(common.TransactionCase): self.assertTrue(chreq.am_i_approver) # approve - chreq.signal_workflow('page_approval_approve') + chreq.page_approval_approved() self.assertEqual(chreq.state, 'approved') self.assertEqual(chreq.content, page.content) @@ -59,7 +58,7 @@ class TestDocumentPageApproval(common.TransactionCase): ('page_id', '=', page.id), ('state', '!=', 'approved') ])[0] - chreq.signal_workflow('page_approval_approve') + chreq.page_approval_approved() self.assertEqual(page.content, 'New content') def test_change_request_auto_approve(self): @@ -75,7 +74,7 @@ class TestDocumentPageApproval(common.TransactionCase): self.history_obj.search([ ('page_id', '=', page.id), ('state', '!=', 'approved') - ]).signal_workflow('page_approval_approve') + ]).page_approval_approved() # new change request from scrath chreq = self.history_obj.create({ @@ -89,25 +88,25 @@ class TestDocumentPageApproval(common.TransactionCase): self.assertNotEqual(page.approved_date, chreq.approved_date) self.assertNotEqual(page.approved_uid, chreq.approved_uid) - chreq.signal_workflow('page_approval_to_approve') + chreq.page_approval_to_approve() self.assertEqual(chreq.state, 'to approve') self.assertNotEqual(page.content, chreq.content) self.assertNotEqual(page.approved_date, chreq.approved_date) self.assertNotEqual(page.approved_uid, chreq.approved_uid) - chreq.signal_workflow('page_approval_cancel') + chreq.page_approval_cancelled() self.assertEqual(chreq.state, 'cancelled') self.assertNotEqual(page.content, chreq.content) self.assertNotEqual(page.approved_date, chreq.approved_date) self.assertNotEqual(page.approved_uid, chreq.approved_uid) - chreq.signal_workflow('page_approval_reopen') + chreq.page_approval_draft() self.assertEqual(chreq.state, 'draft') self.assertNotEqual(page.content, chreq.content) self.assertNotEqual(page.approved_date, chreq.approved_date) self.assertNotEqual(page.approved_uid, chreq.approved_uid) - chreq.signal_workflow('page_approval_approve') + chreq.page_approval_approved() self.assertEqual(chreq.state, 'approved') self.assertEqual(page.content, chreq.content) self.assertEqual(page.approved_date, chreq.approved_date) diff --git a/document_page_approval/views/document_page_approval.xml b/document_page_approval/views/document_page_approval.xml index f6ff140d..3d7ec0cd 100644 --- a/document_page_approval/views/document_page_approval.xml +++ b/document_page_approval/views/document_page_approval.xml @@ -10,19 +10,19 @@
-