document_page_approval migration from Odoo 8.0 to Odoo 9.0

This commit is contained in:
Gervais Naoussi 2015-10-28 10:55:22 -04:00
parent 68f7183856
commit c518b37204
12 changed files with 291 additions and 133 deletions

View File

@ -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 <https://github.com/OCA/
knowledge/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 <https://github.com/OCA/
knowledge/issues/new?body=module:%20
document_page_approval%0Aversion:%20
9.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Contributors
------------
* Odoo SA <info@odoo.com>
* Savoir-faire Linux <support@savoirfairelinux.com>
* Gervais Naoussi <gervaisnaoussi@gmail.com>
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

View File

@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import document_page_approval
from . import models

View File

@ -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',

View File

@ -1,12 +1,12 @@
<?xml version="1.0"?>
<openerp>
<odoo>
<!-- Allow user to make upgrade-proof customizations to email template -->
<data noupdate="1">
<record id="email_template_new_draft_need_approval"
model="email.template">
model="mail.template">
<field name="name">Automated new draft need approval Notification Mail</field>
<field name="email_from">${object.create_uid.company_id.email or 'noreply@localhost.com'}</field>
<field name="subject">New version of "${object.page_id.name}" to approve</field>
@ -28,4 +28,4 @@ Odoo</p>]]>
</record>
</data>
</openerp>
</odoo>

View File

@ -0,0 +1,22 @@
"""Data models initialisation."""
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import document_page_approval, document_page_history_workflow

View File

@ -0,0 +1,127 @@
"""Model DocumentPageApproval."""
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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"
)

View File

@ -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"
)

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<odoo>
<data noupdate="0">
<record id="base.group_document_approver_user" model="res.groups">
<field name="name">Document approver</field>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
</data>
</openerp>
</odoo>

View File

@ -0,0 +1,2 @@
"""Module test initialisation."""
# -*- coding: utf-8 -*-

View File

@ -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

View File

@ -1,5 +1,5 @@
<?xml version="1.0"?>
<openerp>
<odoo>
<data>
<record id="wiki_history_form_inherit" model="ir.ui.view">
<field name="name">document.page.history.form</field>
@ -90,4 +90,4 @@
</field>
</record>
</data>
</openerp>
</odoo>

View File

@ -1,5 +1,5 @@
<?xml version="1.0"?>
<openerp>
<odoo>
<data>
<record model="workflow" id="wkf_document_page_history_aproval">
@ -40,4 +40,4 @@
</data>
</openerp>
</odoo>