mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-16 12:12:57 -06:00
Migrate to 13.0 document_page_approval
To pass test is necesary set approval required to False in demo data
This commit is contained in:
parent
8d8c8ac32a
commit
cd6a16d839
@ -3,12 +3,12 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
"name": "Document Page Approval",
|
"name": "Document Page Approval",
|
||||||
"version": "12.0.1.0.0",
|
"version": "13.0.1.0.0",
|
||||||
"author": "Savoir-faire Linux, Odoo Community Association (OCA)",
|
"author": "Savoir-faire Linux, Odoo Community Association (OCA)",
|
||||||
"website": "http://www.savoirfairelinux.com",
|
"website": "http://www.savoirfairelinux.com",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"category": "Knowledge Management",
|
"category": "Knowledge Management",
|
||||||
"depends": ["document_page", "mail",],
|
"depends": ["document_page", "mail"],
|
||||||
"data": [
|
"data": [
|
||||||
"data/email_template.xml",
|
"data/email_template.xml",
|
||||||
"views/document_page_approval.xml",
|
"views/document_page_approval.xml",
|
||||||
|
@ -22,4 +22,4 @@ def post_init_hook(cr, registry): # pragma: no cover
|
|||||||
def uninstall_hook(cr, registry): # pragma: no cover
|
def uninstall_hook(cr, registry): # pragma: no cover
|
||||||
# Remove unapproved pages
|
# Remove unapproved pages
|
||||||
_logger.info("Deleting unapproved Change Requests.")
|
_logger.info("Deleting unapproved Change Requests.")
|
||||||
cr.execute("DELETE FROM document_page_history " "WHERE state != 'approved'")
|
cr.execute("DELETE FROM document_page_history WHERE state != 'approved'")
|
||||||
|
@ -13,7 +13,7 @@ class DocumentPage(models.Model):
|
|||||||
_inherit = "document.page"
|
_inherit = "document.page"
|
||||||
|
|
||||||
history_ids = fields.One2many(
|
history_ids = fields.One2many(
|
||||||
order="approved_date DESC", domain=[("state", "=", "approved")],
|
order="approved_date DESC", domain=[("state", "=", "approved")]
|
||||||
)
|
)
|
||||||
|
|
||||||
approved_date = fields.Datetime(
|
approved_date = fields.Datetime(
|
||||||
@ -65,10 +65,9 @@ class DocumentPage(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
user_has_drafts = fields.Boolean(
|
user_has_drafts = fields.Boolean(
|
||||||
compute="_compute_user_has_drafts", string="User has drafts?",
|
compute="_compute_user_has_drafts", string="User has drafts?"
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.multi
|
|
||||||
@api.depends("approval_required", "parent_id.is_approval_required")
|
@api.depends("approval_required", "parent_id.is_approval_required")
|
||||||
def _compute_is_approval_required(self):
|
def _compute_is_approval_required(self):
|
||||||
"""Check if the document required approval based on his parents."""
|
"""Check if the document required approval based on his parents."""
|
||||||
@ -78,7 +77,6 @@ class DocumentPage(models.Model):
|
|||||||
res = res or page.parent_id.is_approval_required
|
res = res or page.parent_id.is_approval_required
|
||||||
page.is_approval_required = res
|
page.is_approval_required = res
|
||||||
|
|
||||||
@api.multi
|
|
||||||
@api.depends("approver_gid", "parent_id.approver_group_ids")
|
@api.depends("approver_gid", "parent_id.approver_group_ids")
|
||||||
def _compute_approver_group_ids(self):
|
def _compute_approver_group_ids(self):
|
||||||
"""Compute the approver groups based on his parents."""
|
"""Compute the approver groups based on his parents."""
|
||||||
@ -88,14 +86,12 @@ class DocumentPage(models.Model):
|
|||||||
res = res | page.parent_id.approver_group_ids
|
res = res | page.parent_id.approver_group_ids
|
||||||
page.approver_group_ids = res
|
page.approver_group_ids = res
|
||||||
|
|
||||||
@api.multi
|
|
||||||
@api.depends("is_approval_required", "approver_group_ids")
|
@api.depends("is_approval_required", "approver_group_ids")
|
||||||
def _compute_am_i_approver(self):
|
def _compute_am_i_approver(self):
|
||||||
"""Check if the current user can approve changes to this page."""
|
"""Check if the current user can approve changes to this page."""
|
||||||
for rec in self:
|
for rec in self:
|
||||||
rec.am_i_approver = rec.can_user_approve_this_page(self.env.user)
|
rec.am_i_approver = rec.can_user_approve_this_page(self.env.user)
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def can_user_approve_this_page(self, user):
|
def can_user_approve_this_page(self, user):
|
||||||
"""Check if a user can approve this page."""
|
"""Check if a user can approve this page."""
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
@ -114,7 +110,6 @@ class DocumentPage(models.Model):
|
|||||||
# to approve, user must belong to any of the approver groups
|
# to approve, user must belong to any of the approver groups
|
||||||
return len(user.groups_id & self.approver_group_ids) > 0
|
return len(user.groups_id & self.approver_group_ids) > 0
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def _compute_has_changes_pending_approval(self):
|
def _compute_has_changes_pending_approval(self):
|
||||||
history = self.env["document.page.history"]
|
history = self.env["document.page.history"]
|
||||||
for rec in self:
|
for rec in self:
|
||||||
@ -123,7 +118,6 @@ class DocumentPage(models.Model):
|
|||||||
)
|
)
|
||||||
rec.has_changes_pending_approval = changes > 0
|
rec.has_changes_pending_approval = changes > 0
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def _compute_user_has_drafts(self):
|
def _compute_user_has_drafts(self):
|
||||||
history = self.env["document.page.history"]
|
history = self.env["document.page.history"]
|
||||||
for rec in self:
|
for rec in self:
|
||||||
@ -132,12 +126,10 @@ class DocumentPage(models.Model):
|
|||||||
)
|
)
|
||||||
rec.user_has_drafts = changes > 0
|
rec.user_has_drafts = changes > 0
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def _create_history(self, vals):
|
def _create_history(self, vals):
|
||||||
res = super(DocumentPage, self)._create_history(vals)
|
res = super(DocumentPage, self)._create_history(vals)
|
||||||
res.action_to_approve()
|
res.action_to_approve()
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def action_changes_pending_approval(self):
|
def action_changes_pending_approval(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
action = self.env.ref("document_page_approval.action_change_requests")
|
action = self.env.ref("document_page_approval.action_change_requests")
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
|
# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import api, fields, models
|
from odoo import fields, models
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
from odoo.tools.translate import _
|
from odoo.tools.translate import _
|
||||||
|
|
||||||
@ -24,21 +24,20 @@ class DocumentPageHistory(models.Model):
|
|||||||
readonly=True,
|
readonly=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
approved_date = fields.Datetime("Approved Date",)
|
approved_date = fields.Datetime("Approved Date")
|
||||||
|
|
||||||
approved_uid = fields.Many2one("res.users", "Approved by",)
|
approved_uid = fields.Many2one("res.users", "Approved by")
|
||||||
|
|
||||||
is_approval_required = fields.Boolean(
|
is_approval_required = fields.Boolean(
|
||||||
related="page_id.is_approval_required", string="Approval required",
|
related="page_id.is_approval_required", string="Approval required"
|
||||||
)
|
)
|
||||||
|
|
||||||
am_i_owner = fields.Boolean(compute="_compute_am_i_owner")
|
am_i_owner = fields.Boolean(compute="_compute_am_i_owner")
|
||||||
|
|
||||||
am_i_approver = fields.Boolean(related="page_id.am_i_approver", related_sudo=False,)
|
am_i_approver = fields.Boolean(related="page_id.am_i_approver", related_sudo=False)
|
||||||
|
|
||||||
page_url = fields.Text(compute="_compute_page_url", string="URL",)
|
page_url = fields.Text(compute="_compute_page_url", string="URL")
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def action_draft(self):
|
def action_draft(self):
|
||||||
"""Set a change request as draft"""
|
"""Set a change request as draft"""
|
||||||
for rec in self:
|
for rec in self:
|
||||||
@ -53,7 +52,6 @@ class DocumentPageHistory(models.Model):
|
|||||||
)
|
)
|
||||||
rec.write({"state": "draft"})
|
rec.write({"state": "draft"})
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def action_to_approve(self):
|
def action_to_approve(self):
|
||||||
"""Set a change request as to approve"""
|
"""Set a change request as to approve"""
|
||||||
template = self.env.ref(
|
template = self.env.ref(
|
||||||
@ -85,7 +83,6 @@ class DocumentPageHistory(models.Model):
|
|||||||
# auto-approve if approval is not required
|
# auto-approve if approval is not required
|
||||||
rec.action_approve()
|
rec.action_approve()
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def action_approve(self):
|
def action_approve(self):
|
||||||
"""Set a change request as approved."""
|
"""Set a change request as approved."""
|
||||||
for rec in self:
|
for rec in self:
|
||||||
@ -123,7 +120,6 @@ class DocumentPageHistory(models.Model):
|
|||||||
body=_("New version of the document %s approved.") % (rec.page_id.name),
|
body=_("New version of the document %s approved.") % (rec.page_id.name),
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def action_cancel(self):
|
def action_cancel(self):
|
||||||
"""Set a change request as cancelled."""
|
"""Set a change request as cancelled."""
|
||||||
self.write({"state": "cancelled"})
|
self.write({"state": "cancelled"})
|
||||||
@ -134,19 +130,16 @@ class DocumentPageHistory(models.Model):
|
|||||||
% (rec.display_name, self.env.user.name),
|
% (rec.display_name, self.env.user.name),
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def action_cancel_and_draft(self):
|
def action_cancel_and_draft(self):
|
||||||
"""Set a change request as draft, cancelling it first"""
|
"""Set a change request as draft, cancelling it first"""
|
||||||
self.action_cancel()
|
self.action_cancel()
|
||||||
self.action_draft()
|
self.action_draft()
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def _compute_am_i_owner(self):
|
def _compute_am_i_owner(self):
|
||||||
"""Check if current user is the owner"""
|
"""Check if current user is the owner"""
|
||||||
for rec in self:
|
for rec in self:
|
||||||
rec.am_i_owner = rec.create_uid == self.env.user
|
rec.am_i_owner = rec.create_uid == self.env.user
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def _compute_page_url(self):
|
def _compute_page_url(self):
|
||||||
"""Compute the page url."""
|
"""Compute the page url."""
|
||||||
for page in self:
|
for page in self:
|
||||||
@ -157,10 +150,9 @@ class DocumentPageHistory(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
page.page_url = (
|
page.page_url = (
|
||||||
"{}/web#db={}&id={}&view_type=form&" "model=document.page.history"
|
"{}/web#db={}&id={}&" "model=document.page.history"
|
||||||
).format(base_url, self.env.cr.dbname, page.id)
|
).format(base_url, self.env.cr.dbname, page.id)
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def _compute_diff(self):
|
def _compute_diff(self):
|
||||||
"""Shows a diff between this version and the previous version"""
|
"""Shows a diff between this version and the previous version"""
|
||||||
history = self.env["document.page.history"]
|
history = self.env["document.page.history"]
|
||||||
|
@ -4,3 +4,7 @@
|
|||||||
* Maxime Chambreuil <mchambreuil@opensourceintegrators.com>
|
* Maxime Chambreuil <mchambreuil@opensourceintegrators.com>
|
||||||
* Iván Todorovich <ivan.todorovich@gmail.com>
|
* Iván Todorovich <ivan.todorovich@gmail.com>
|
||||||
* Victor M.M. Torres <victor.martin@tecnativa.com>
|
* Victor M.M. Torres <victor.martin@tecnativa.com>
|
||||||
|
|
||||||
|
* `Guadaltech <https://www.guadaltech.es>`_:
|
||||||
|
|
||||||
|
* Fernando La Chica <fernando.lachica@guadaltech.es>
|
||||||
|
@ -367,7 +367,7 @@ ul.auto-toc {
|
|||||||
!! This file is generated by oca-gen-addon-readme !!
|
!! This file is generated by oca-gen-addon-readme !!
|
||||||
!! changes will be overwritten. !!
|
!! changes will be overwritten. !!
|
||||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||||
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/knowledge/tree/12.0/document_page_approval"><img alt="OCA/knowledge" src="https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/knowledge-12-0/knowledge-12-0-document_page_approval"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/118/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
|
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/knowledge/tree/13.0/document_page_approval"><img alt="OCA/knowledge" src="https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/knowledge-12-0/knowledge-12-0-document_page_approval"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/118/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
|
||||||
<p>This module adds a workflow to approve page modifications
|
<p>This module adds a workflow to approve page modifications
|
||||||
and show the approved version by default.</p>
|
and show the approved version by default.</p>
|
||||||
<p><strong>Table of contents</strong></p>
|
<p><strong>Table of contents</strong></p>
|
||||||
@ -411,7 +411,7 @@ page history to review.</li>
|
|||||||
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/knowledge/issues">GitHub Issues</a>.
|
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/knowledge/issues">GitHub Issues</a>.
|
||||||
In case of trouble, please check there if your issue has already been reported.
|
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
|
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||||
<a class="reference external" href="https://github.com/OCA/knowledge/issues/new?body=module:%20document_page_approval%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
|
<a class="reference external" href="https://github.com/OCA/knowledge/issues/new?body=module:%20document_page_approval%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
|
||||||
<p>Do not contact contributors directly about support or help with technical issues.</p>
|
<p>Do not contact contributors directly about support or help with technical issues.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="credits">
|
<div class="section" id="credits">
|
||||||
@ -440,7 +440,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
|
|||||||
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
|
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||||
mission is to support the collaborative development of Odoo features and
|
mission is to support the collaborative development of Odoo features and
|
||||||
promote its widespread use.</p>
|
promote its widespread use.</p>
|
||||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/knowledge/tree/12.0/document_page_approval">OCA/knowledge</a> project on GitHub.</p>
|
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/knowledge/tree/13.0/document_page_approval">OCA/knowledge</a> project on GitHub.</p>
|
||||||
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
|
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -12,9 +12,7 @@ class TestDocumentPageApproval(common.TransactionCase):
|
|||||||
self.approver_gid = self.env.ref(
|
self.approver_gid = self.env.ref(
|
||||||
"document_page_approval.group_document_approver_user"
|
"document_page_approval.group_document_approver_user"
|
||||||
)
|
)
|
||||||
self.env.ref("base.user_root").write(
|
self.env.ref("base.user_root").write({"groups_id": [(4, self.approver_gid.id)]})
|
||||||
{"groups_id": [(4, self.approver_gid.id)],}
|
|
||||||
)
|
|
||||||
# demo_approval
|
# demo_approval
|
||||||
self.category2 = self.page_obj.create(
|
self.category2 = self.page_obj.create(
|
||||||
{
|
{
|
||||||
@ -46,6 +44,9 @@ class TestDocumentPageApproval(common.TransactionCase):
|
|||||||
|
|
||||||
# It should automatically be in 'to approve' state
|
# It should automatically be in 'to approve' state
|
||||||
self.assertEqual(chreq.state, "to approve")
|
self.assertEqual(chreq.state, "to approve")
|
||||||
|
|
||||||
|
# Needed to compute calculated fields
|
||||||
|
page.refresh()
|
||||||
self.assertNotEqual(chreq.content, page.content)
|
self.assertNotEqual(chreq.content, page.content)
|
||||||
|
|
||||||
# who_am_i
|
# who_am_i
|
||||||
@ -59,6 +60,8 @@ class TestDocumentPageApproval(common.TransactionCase):
|
|||||||
|
|
||||||
# new changes should create change requests
|
# new changes should create change requests
|
||||||
page.write({"content": "New content"})
|
page.write({"content": "New content"})
|
||||||
|
# Needed to compute calculated fields
|
||||||
|
page.refresh()
|
||||||
self.assertNotEqual(page.content, "New content")
|
self.assertNotEqual(page.content, "New content")
|
||||||
chreq = self.history_obj.search(
|
chreq = self.history_obj.search(
|
||||||
[("page_id", "=", page.id), ("state", "!=", "approved")]
|
[("page_id", "=", page.id), ("state", "!=", "approved")]
|
||||||
|
@ -164,7 +164,7 @@
|
|||||||
<field name="has_changes_pending_approval" invisible="1" />
|
<field name="has_changes_pending_approval" invisible="1" />
|
||||||
<field name="user_has_drafts" invisible="1" />
|
<field name="user_has_drafts" invisible="1" />
|
||||||
</sheet>
|
</sheet>
|
||||||
<button name="toggle_active" position="after">
|
<xpath expr="//div[@name='button_box']" position="inside">
|
||||||
<button
|
<button
|
||||||
class="oe_stat_button"
|
class="oe_stat_button"
|
||||||
name="action_changes_pending_approval"
|
name="action_changes_pending_approval"
|
||||||
@ -173,7 +173,7 @@
|
|||||||
attrs="{'invisible':[('has_changes_pending_approval','=',False),('user_has_drafts','=',False)]}"
|
attrs="{'invisible':[('has_changes_pending_approval','=',False),('user_has_drafts','=',False)]}"
|
||||||
icon="fa-edit"
|
icon="fa-edit"
|
||||||
/>
|
/>
|
||||||
</button>
|
</xpath>
|
||||||
<field name="content_uid" position="after">
|
<field name="content_uid" position="after">
|
||||||
<field name="approved_uid" />
|
<field name="approved_uid" />
|
||||||
</field>
|
</field>
|
||||||
@ -288,7 +288,6 @@
|
|||||||
<record model="ir.actions.act_window" id="action_change_requests">
|
<record model="ir.actions.act_window" id="action_change_requests">
|
||||||
<field name="name">Change Requests</field>
|
<field name="name">Change Requests</field>
|
||||||
<field name="res_model">document.page.history</field>
|
<field name="res_model">document.page.history</field>
|
||||||
<field name="view_type">form</field>
|
|
||||||
<field name="view_mode">tree,form</field>
|
<field name="view_mode">tree,form</field>
|
||||||
<field
|
<field
|
||||||
name="context"
|
name="context"
|
||||||
|
Loading…
Reference in New Issue
Block a user