diff --git a/document_page_approval/README.rst b/document_page_approval/README.rst
index ab1a0f50..7f3d78af 100644
--- a/document_page_approval/README.rst
+++ b/document_page_approval/README.rst
@@ -58,6 +58,7 @@ Contributors
* Savoir-faire Linux
* Gervais Naoussi
* Maxime Chambreuil
+* Iván Todorovich
Maintainer
----------
diff --git a/document_page_approval/__init__.py b/document_page_approval/__init__.py
index 01c2ffde..a9f5c87d 100644
--- a/document_page_approval/__init__.py
+++ b/document_page_approval/__init__.py
@@ -3,3 +3,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models
+from .hooks import post_init_hook, uninstall_hook
diff --git a/document_page_approval/__manifest__.py b/document_page_approval/__manifest__.py
index 88ba7210..a2403bbb 100644
--- a/document_page_approval/__manifest__.py
+++ b/document_page_approval/__manifest__.py
@@ -4,7 +4,7 @@
{
'name': 'Document Page Approval',
- 'version': '10.0.1.1.0',
+ 'version': '10.0.2.0.0',
"author": "Savoir-faire Linux, Odoo Community Association (OCA)",
"website": "http://www.savoirfairelinux.com",
"license": "AGPL-3",
@@ -25,4 +25,6 @@
'images/page_history_list.png',
'images/page_history.png',
],
+ 'post_init_hook': 'post_init_hook',
+ 'uninstall_hook': 'uninstall_hook',
}
diff --git a/document_page_approval/data/email_template.xml b/document_page_approval/data/email_template.xml
index e3bc566d..6118c5f8 100644
--- a/document_page_approval/data/email_template.xml
+++ b/document_page_approval/data/email_template.xml
@@ -1,12 +1,11 @@
-
+
-
+
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
- ${object.get_approvers_email}
+ New version of ${object.display_name} needs your approval
${object.create_uid.partner_id.lang}
@@ -14,13 +13,30 @@
Hello,
-The page "${object.page_id.name}" has been modified and need your approval.
+${object.create_uid.name} submited a new Change Request for ${object.page_id.name} and it needs your approval.
-You can review the new version here : ${object.get_page_url}
+
+
+Modified by: ${object.create_uid.name}
+Date: ${object.create_date}
+
+
+% if object.summary:
+Summary
+${object.summary}
+% endif
+
+Diff
+
+${object.diff|safe}
+
+
+Have a great day.
-Have a great day.
--
-Odoo
]]>
+
+Odoo
+ ]]>
diff --git a/document_page_approval/hooks.py b/document_page_approval/hooks.py
new file mode 100644
index 00000000..4e02a759
--- /dev/null
+++ b/document_page_approval/hooks.py
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+# Copyright 2018 Ivan Todorovich ()
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+
+
+def post_init_hook(cr, registry): # 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
+ """)
+
+
+def uninstall_hook(cr, registry): # pragma: no cover
+ # Remove unapproved pages
+ cr.execute(
+ "DELETE FROM document_page_history "
+ "WHERE state != 'approved'"
+ )
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
new file mode 100644
index 00000000..b9fd8954
--- /dev/null
+++ b/document_page_approval/migrations/10.0.2.0.0/post-migration.py
@@ -0,0 +1,14 @@
+# -*- 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/document_page_approval.py b/document_page_approval/models/document_page_approval.py
index 388dae9a..5ff46dfe 100644
--- a/document_page_approval/models/document_page_approval.py
+++ b/document_page_approval/models/document_page_approval.py
@@ -2,7 +2,9 @@
# Copyright (C) 2013 Savoir-faire Linux ().
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-from openerp import api, fields, models
+
+from odoo import api, fields, models
+from ast import literal_eval
class DocumentPageApproval(models.Model):
@@ -10,104 +12,126 @@ class DocumentPageApproval(models.Model):
_inherit = 'document.page'
- @api.multi
- 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
-
- @api.multi
- 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
-
- @api.multi
- 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
-
- @api.multi
- def _is_parent_approval_required(self):
- """Check if the document requires approval base on his parent."""
- for page in self:
- page.is_parent_approval_required = self.is_approval_required(page)
-
- def is_approval_required(self, page):
- """Check if a document requires 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'
+ history_ids = fields.One2many(
+ order='approved_date DESC',
+ domain=[('state', '=', 'approved')],
)
approved_date = fields.Datetime(
- compute=_get_approved_date,
- string="Approved Date"
+ 'Approved Date',
+ related='history_head.approved_date',
+ store=True,
+ index=True,
+ readonly=True,
)
approved_uid = fields.Many2one(
'res.users',
- compute=_get_approved_uid,
- string="Approved By",
+ 'Approved by',
+ related='history_head.approved_uid',
+ store=True,
+ index=True,
+ readonly=True,
)
- approval_required = fields.Boolean("Require approval")
-
- is_parent_approval_required = fields.Boolean(
- compute=_is_parent_approval_required,
- string="parent approval"
+ approval_required = fields.Boolean(
+ 'Require approval',
+ help='Require approval for changes on this page or its child pages.',
)
approver_gid = fields.Many2one(
"res.groups",
- "Approver group"
+ "Approver group",
+ help='Users must also belong to the Approvers group',
)
+
+ is_approval_required = fields.Boolean(
+ 'Approval required',
+ help='If true, changes of this page require approval',
+ compute='_compute_is_approval_required',
+ )
+
+ am_i_approver = fields.Boolean(
+ compute='_compute_am_i_approver'
+ )
+
+ approver_group_ids = fields.Many2many(
+ 'res.groups',
+ string='Approver groups',
+ help='Groups that can approve changes to this document',
+ compute='_compute_approver_group_ids',
+ )
+
+ has_changes_pending_approval = fields.Boolean(
+ compute='_compute_has_changes_pending_approval',
+ string='Has changes pending approval'
+ )
+
+ @api.multi
+ @api.depends('approval_required', 'parent_id.is_approval_required')
+ def _compute_is_approval_required(self):
+ """Check if the document required approval based on his parents."""
+ for page in self:
+ res = page.approval_required
+ if page.parent_id:
+ res = res or page.parent_id.is_approval_required
+ page.is_approval_required = res
+
+ @api.multi
+ @api.depends('approver_gid', 'parent_id.approver_group_ids')
+ def _compute_approver_group_ids(self):
+ """Compute the approver groups based on his parents."""
+ for page in self:
+ res = page.approver_gid
+ if page.parent_id:
+ res = res | page.parent_id.approver_group_ids
+ page.approver_group_ids = res
+
+ @api.multi
+ @api.depends('is_approval_required', 'approver_group_ids')
+ def _compute_am_i_approver(self):
+ """Check if the current user can approve changes to this page."""
+ for rec in self:
+ rec.am_i_approver = rec.can_user_approve_this_page(self.env.user)
+
+ @api.multi
+ def can_user_approve_this_page(self, user):
+ """Check if a user can approve this page."""
+ self.ensure_one()
+ # if it's not required, anyone can approve
+ if not self.is_approval_required:
+ return True
+ # to approve, you must have approver rights
+ approver_group_id = self.env.ref(
+ 'document_page_approval.group_document_approver_user')
+ if approver_group_id not in user.groups_id:
+ return False
+ # and belong to at least one of the approver_groups (if any is set)
+ if not self.approver_group_ids:
+ return True
+ return len(user.groups_id & self.approver_group_ids) > 0
+
+ @api.multi
+ def _compute_has_changes_pending_approval(self):
+ history = self.env['document.page.history']
+ for rec in self:
+ changes = history.search_count([
+ ('page_id', '=', rec.id),
+ ('state', '=', 'to approve')])
+ rec.has_changes_pending_approval = (changes > 0)
+
+ @api.multi
+ def _create_history(self, vals):
+ res = super(DocumentPageApproval, self)._create_history(vals)
+ res.signal_workflow('document_page_auto_confirm')
+
+ @api.multi
+ def action_changes_pending_approval(self):
+ self.ensure_one()
+ action = self.env.ref('document_page_approval.action_change_requests')
+ action = action.read()[0]
+ context = literal_eval(action['context'])
+ context['search_default_page_id'] = self.id
+ context['default_page_id'] = self.id
+ action['context'] = context
+ return action
diff --git a/document_page_approval/models/document_page_history_workflow.py b/document_page_approval/models/document_page_history_workflow.py
index 82ba943d..a745ea58 100644
--- a/document_page_approval/models/document_page_history_workflow.py
+++ b/document_page_approval/models/document_page_history_workflow.py
@@ -11,117 +11,122 @@ from odoo import api, fields, models
class DocumentPageHistoryWorkflow(models.Model):
"""Useful to manage edition's workflow on a document."""
- _inherit = 'document.page.history'
+ _name = 'document.page.history'
+ _inherit = ['document.page.history', 'mail.thread']
+
+ state = fields.Selection([
+ ('draft', 'Draft'),
+ ('to approve', 'Pending Approval'),
+ ('approved', 'Approved'),
+ ('cancelled', 'Cancelled')],
+ 'Status',
+ readonly=True,
+ )
+
+ approved_date = fields.Datetime(
+ 'Approved Date',
+ )
+
+ approved_uid = fields.Many2one(
+ 'res.users',
+ 'Approved by',
+ )
+
+ is_approval_required = fields.Boolean(
+ related='page_id.is_approval_required',
+ string="Approval required",
+ )
+
+ am_i_owner = fields.Boolean(
+ compute='_compute_am_i_owner'
+ )
+
+ am_i_approver = fields.Boolean(
+ related='page_id.am_i_approver'
+ )
+
+ page_url = fields.Text(
+ compute='_compute_page_url',
+ string="URL",
+ )
@api.multi
def page_approval_draft(self):
- """Set a document state as draft and notified the reviewers."""
+ """Set a change request as draft"""
self.write({'state': 'draft'})
+
+ @api.multi
+ def page_approval_to_approve(self):
+ """Set a change request as to approve"""
+ self.write({'state': 'to approve'})
template = self.env.ref(
'document_page_approval.email_template_new_draft_need_approval')
- for page in self:
- if page.is_parent_approval_required:
- template.send_mail(page.id, force_send=True)
- return True
+ approver_gid = self.env.ref(
+ 'document_page_approval.group_document_approver_user')
+ for rec in self:
+ if rec.is_approval_required:
+ guids = [g.id for g in rec.page_id.approver_group_ids]
+ users = self.env['res.users'].search([
+ ('groups_id', 'in', guids),
+ ('groups_id', 'in', approver_gid.id)])
+ rec.message_subscribe_users([u.id for u in users])
+ rec.message_post_with_template(template.id)
@api.multi
def page_approval_approved(self):
- """Set a document state as approve."""
- message_obj = self.env['mail.message']
+ """Set a change request as approved."""
self.write({
'state': 'approved',
'approved_date': datetime.now().strftime(
DEFAULT_SERVER_DATETIME_FORMAT),
'approved_uid': self.env.uid
})
- # Notify followers a new version is available
- for page_history in self:
- subtype = self.env.ref('mail.mt_comment')
- message_obj.create(
- {'res_id': page_history.page_id.id,
- 'model': 'document.page',
- 'subtype_id': subtype.id,
- 'body': _('New version of the document %s'
- ' approved.') % page_history.page_id.name
- }
+ for rec in self:
+ # Trigger computed field update
+ rec.page_id._compute_history_head()
+ # Notify state change
+ rec.message_post(
+ subtype='mt_comment',
+ body=_(
+ 'Change request has been approved by %s.'
+ ) % (self.env.user.name)
)
- return True
-
- @api.multi
- 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(
- page.page_id,
- user
+ # Notify followers a new version is available
+ rec.page_id.message_post(
+ subtype='mt_comment',
+ body=_(
+ 'New version of the document %s approved.'
+ ) % (rec.page_id.name)
)
- 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)
- else:
- res = False
- return res
+ @api.multi
+ def page_approval_cancelled(self):
+ """Set a change request as cancelled."""
+ self.write({'state': 'cancelled'})
+ for rec in self:
+ rec.message_post(
+ subtype='mt_comment',
+ body=_(
+ 'Change request %s has been cancelled by %s.'
+ ) % (rec.display_name, self.env.user.name)
+ )
@api.multi
- 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]
- else:
- res = []
- res.extend(self.get_approvers_guids_for_page(page.parent_id))
- else:
- res = []
-
- return res
+ def _compute_am_i_owner(self):
+ """Check if current user is the owner"""
+ for rec in self:
+ rec.am_i_owner = (rec.create_uid == self.env.user)
@api.multi
- def _get_approvers_email(self):
- """Get the approvers email."""
- for page in self:
- emails = ''
- guids = self.get_approvers_guids()
- uids = [i.id for i in self.env['res.users'].search([
- ('groups_id', 'in', guids[page.id])
- ])]
- users = self.env['res.users'].browse(uids)
-
- for user in users:
- if user.email:
- emails += user.email
- emails += ','
- else:
- empl = self.env['hr.employee'].search([
- ('login', '=', user.login)
- ])
- if empl.work_email:
- emails += empl.work_email
- emails += ','
-
- page.get_approvers_email = emails[:-1]
-
- @api.multi
- def _get_page_url(self):
- """Get the page url."""
+ def _compute_page_url(self):
+ """Compute the page url."""
for page in self:
base_url = self.env['ir.config_parameter'].get_param(
'web.base.url',
default='http://localhost:8069'
)
- page.get_page_url = (
+ page.page_url = (
'{}/web#db={}&id={}&view_type=form&'
'model=document.page.history').format(
base_url,
@@ -129,37 +134,18 @@ class DocumentPageHistoryWorkflow(models.Model):
page.id
)
- state = fields.Selection(
- [('draft', 'Draft'), ('approved', 'Approved')],
- 'Status',
- readonly=True
- )
-
- approved_date = fields.Datetime("Approved Date")
-
- approved_uid = fields.Many2one(
- 'res.users',
- "Approved By"
- )
-
- is_parent_approval_required = fields.Boolean(
- related='page_id.is_parent_approval_required',
- string="parent approval",
- store=False
- )
-
- can_user_approve_page = fields.Boolean(
- compute=_can_user_approve_page,
- string="can user approve this page",
- store=False
- )
- get_approvers_email = fields.Text(
- compute=_get_approvers_email,
- string="get all approvers email",
- store=False
- )
- get_page_url = fields.Text(
- compute=_get_page_url,
- string="URL",
- store=False
- )
+ @api.multi
+ def _compute_diff(self):
+ """Shows a diff between this version and the previous version"""
+ history = self.env['document.page.history']
+ for rec in self:
+ domain = [
+ ('page_id', '=', rec.page_id.id),
+ ('state', '=', 'approved')]
+ if rec.approved_date:
+ domain.append(('approved_date', '<', rec.approved_date))
+ prev = history.search(domain, limit=1, order='approved_date DESC')
+ if prev:
+ rec.diff = self.getDiff(prev.id, rec.id)
+ else:
+ rec.diff = self.getDiff(False, rec.id)
diff --git a/document_page_approval/security/document_page_security.xml b/document_page_approval/security/document_page_security.xml
index f0378d8e..ab80c13f 100644
--- a/document_page_approval/security/document_page_security.xml
+++ b/document_page_approval/security/document_page_security.xml
@@ -2,8 +2,13 @@
- Document approver
-
+ Approver
+
+
+
+
+
+
diff --git a/document_page_approval/security/ir.model.access.csv b/document_page_approval/security/ir.model.access.csv
index f8e75f15..97dd8b91 100644
--- a/document_page_approval/security/ir.model.access.csv
+++ b/document_page_approval/security/ir.model.access.csv
@@ -1,2 +1 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
-document_page_history,document.page.history,model_document_page_history,group_document_approver_user,1,1,1,0
diff --git a/document_page_approval/tests/__init__.py b/document_page_approval/tests/__init__.py
index 2413da81..30782b8b 100644
--- a/document_page_approval/tests/__init__.py
+++ b/document_page_approval/tests/__init__.py
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
-from . import test_document_page_approval, test_document_page_history_workflow
+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 4c0e8457..5e4f89b5 100644
--- a/document_page_approval/tests/test_document_page_approval.py
+++ b/document_page_approval/tests/test_document_page_approval.py
@@ -1,37 +1,125 @@
# -*- coding: utf-8 -*-
-from openerp.tests import common
+from odoo.tests import common
class TestDocumentPageApproval(common.TransactionCase):
- """Test document page approval model."""
- 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 setUp(self):
+ super(TestDocumentPageApproval, self).setUp()
+ self.page_obj = self.env['document.page']
+ self.history_obj = self.env['document.page.history']
+ # demo
+ self.category1 = self.env.ref('document_page.demo_category1')
+ self.page1 = self.env.ref('document_page.demo_page1')
+ self.approver_gid = self.env.ref(
+ 'document_page_approval.group_document_approver_user')
+ # demo_approval
+ self.category2 = self.page_obj.create({
+ 'name': 'This category requires approval',
+ 'type': 'category',
+ 'approval_required': True,
+ 'approver_gid': self.approver_gid.id,
+ })
+ self.page2 = self.page_obj.create({
+ 'name': 'This page requires approval',
+ 'parent_id': self.category2.id,
+ 'content': 'This content will require approval'
+ })
- self.assertIsNotNone(category.display_content, 'a category')
+ def test_approval_required(self):
+ page = self.page2
+ self.assertTrue(page.is_approval_required)
+ self.assertTrue(page.has_changes_pending_approval)
+ self.assertEqual(len(page.history_ids), 0)
- # Check content of a page
- pages = self.env['document.page'].search([
- ('parent_id', '=', category.id)
- ])
+ def test_change_request_approve(self):
+ page = self.page2
+ chreq = self.history_obj.search([
+ ('page_id', '=', page.id),
+ ('state', '!=', 'approved')
+ ])[0]
+
+ # It should automatically be in 'to approve' state
+ self.assertEqual(chreq.state, 'to approve')
+ self.assertNotEqual(chreq.content, page.content)
+
+ # who_am_i
+ self.assertTrue(chreq.am_i_owner)
+ self.assertTrue(chreq.am_i_approver)
+
+ # approve
+ chreq.signal_workflow('page_approval_approve')
+ self.assertEqual(chreq.state, 'approved')
+ self.assertEqual(chreq.content, page.content)
+
+ # new changes should create change requests
+ page.write({'content': 'New content'})
+ self.assertNotEqual(page.content, 'New content')
+ chreq = self.history_obj.search([
+ ('page_id', '=', page.id),
+ ('state', '!=', 'approved')
+ ])[0]
+ chreq.signal_workflow('page_approval_approve')
+ self.assertEqual(page.content, 'New content')
+
+ def test_change_request_auto_approve(self):
+ page = self.page1
+ self.assertFalse(page.is_approval_required)
+ page.write({'content': 'New content'})
+ self.assertEqual(page.content, 'New content')
+
+ def test_change_request_from_scratch(self):
+ page = self.page2
+
+ # aprove everything
+ self.history_obj.search([
+ ('page_id', '=', page.id),
+ ('state', '!=', 'approved')
+ ]).signal_workflow('page_approval_approve')
+
+ # new change request from scrath
+ chreq = self.history_obj.create({
+ 'page_id': page.id,
+ 'summary': 'Changed something',
+ 'content': 'New content',
+ })
+
+ 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_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')
+ 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')
+ 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')
+ self.assertEqual(chreq.state, 'approved')
+ self.assertEqual(page.content, chreq.content)
+ self.assertEqual(page.approved_date, chreq.approved_date)
+ self.assertEqual(page.approved_uid, chreq.approved_uid)
+
+ def test_get_approvers_guids(self):
+ """Get approver guids."""
+ page = self.page2
+ self.assertTrue(len(page.approver_group_ids) > 0)
+
+ def test_get_page_url(self):
+ """Test if page url exist."""
+ pages = self.env['document.page.history'].search([])
page = pages[0]
- self.assertIsNotNone(page.display_content, 'Page content')
-
- # Check if approval is required
- self.assertTrue(page.is_approval_required(page) ==
- category.approval_required)
-
- # 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.assertTrue(page.is_parent_approval_required)
+ self.assertIsNotNone(page.page_url)
diff --git a/document_page_approval/tests/test_document_page_history_workflow.py b/document_page_approval/tests/test_document_page_history_workflow.py
deleted file mode 100644
index 508aff80..00000000
--- a/document_page_approval/tests/test_document_page_history_workflow.py
+++ /dev/null
@@ -1,67 +0,0 @@
-# -*- 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."""
- category = self.env.ref('document_page.demo_category1')
- category.approval_required = True
- category.approver_gid = self.env.ref(
- 'document_page_approval.group_document_approver_user')
-
- page = self.env['document.page'].create({
- 'name': 'Test Page10',
- 'content': 'A difficult test',
- 'parent_id': category.id
- })
-
- history = self.env['document.page.history'].search(
- [
- ('page_id', '=', page.id)
- ],
- limit=1,
- order='create_date DESC'
- )
-
- self.assertTrue(history.can_user_approve_page)
-
- 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)
diff --git a/document_page_approval/views/document_page_approval.xml b/document_page_approval/views/document_page_approval.xml
index ce505bab..f6ff140d 100644
--- a/document_page_approval/views/document_page_approval.xml
+++ b/document_page_approval/views/document_page_approval.xml
@@ -1,92 +1,189 @@
-
- document.page.history.form
- document.page.history
-
-
-
-
-
+
+
+ document.page.history.form
+ document.page.history
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {'readonly': [('state', 'not in', ['draft'])]}
-
+
+
+
+
+
+
+
+
-
- document.page.form
- document.page
-
-
-
-
-
-
-
-
-
-
+
+
+ document.page.form
+ document.page
+
+
-
+
+
+ This document has Changes Pending Approval. You are viewing the last approved content.
+
+
+ This document requires approval. If edited, you will create a new Change Request.
+
+
+
+
-
- document.page.category.form
- document.page
-
-
-
-
-
-
+
+
+
+
-
-
- document.page.history.tree
- document.page.history
-
-
-
-
-
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ document.page.category.form
+ document.page
+
+
+
+
+
+
+
+
+
+
+
+ document.page.history.tree
+ document.page.history
+
+
+
+ state=='draft'
+ state=='to approve'
+ state=='cancelled'
+
+
+
+
+
+
+
+
+
+
+
+
+ document.page.history.search
+ document.page.history
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Change Requests
+ document.page.history
+ form
+ tree,form
+ {'search_default_state':'to approve'}
+
+
+
diff --git a/document_page_approval/workflows/document_page_approval.xml b/document_page_approval/workflows/document_page_approval.xml
index 410d8a54..51d01ad9 100644
--- a/document_page_approval/workflows/document_page_approval.xml
+++ b/document_page_approval/workflows/document_page_approval.xml
@@ -1,40 +1,104 @@
-
- document.page.history.aproval.wkf
- document.page.history
- True
-
+
+ document.page.history.aproval.wkf
+ document.page.history
+ True
+
-
-
- approved
- function
- page_approval_approved()
- True
-
+
+
+ True
+ draft
+ function
+ page_approval_draft()
+
-
-
- True
- draft
- function
- page_approval_draft()
-
+
+
+ to approve
+ function
+ page_approval_to_approve()
+
-
-
-
- page_approval_approve
-
+
+
+ approved
+ function
+ page_approval_approved()
+ True
+
-
-
-
- edit
-
+
+
+ cancelled
+ function
+ page_approval_cancelled()
+
+
+
+
+
+ am_i_owner
+ page_approval_to_approve
+
+
+
+
+
+ am_i_approver
+ page_approval_approve
+
+
+
+
+
+ am_i_approver
+ page_approval_approve
+
+
+
+
+
+ am_i_approver
+ edit
+
+
+
+
+
+ am_i_owner
+ page_approval_cancel
+
+
+
+
+
+ am_i_owner or am_i_approver
+ page_approval_cancel
+
+
+
+
+
+ am_i_owner or am_i_approver
+ page_approval_reopen
+
+
+
+
+
+
+ not is_approval_required
+ document_page_auto_confirm
+
+
+
+
+
+ is_approval_required
+ document_page_auto_confirm
+