From 32b684c65f6bb04261adaebff7042f66b1afe19e Mon Sep 17 00:00:00 2001
From: flachica
Date: Sat, 4 Jul 2020 19:13:10 +0200
Subject: [PATCH] Migrate to 13.0 document_page_approval
To pass test is necesary set approval required to False in demo data
---
document_page_approval/__manifest__.py | 4 ++--
document_page_approval/hooks.py | 2 +-
.../models/document_page.py | 12 ++--------
.../models/document_page_history.py | 22 ++++++-------------
.../readme/CONTRIBUTORS.rst | 4 ++++
.../static/description/index.html | 6 ++---
.../tests/test_document_page_approval.py | 9 +++++---
.../views/document_page_approval.xml | 5 ++---
8 files changed, 27 insertions(+), 37 deletions(-)
diff --git a/document_page_approval/__manifest__.py b/document_page_approval/__manifest__.py
index 57fd9b68..3c4bd5d2 100644
--- a/document_page_approval/__manifest__.py
+++ b/document_page_approval/__manifest__.py
@@ -3,12 +3,12 @@
{
"name": "Document Page Approval",
- "version": "12.0.1.0.0",
+ "version": "13.0.1.0.0",
"author": "Savoir-faire Linux, Odoo Community Association (OCA)",
"website": "http://www.savoirfairelinux.com",
"license": "AGPL-3",
"category": "Knowledge Management",
- "depends": ["document_page", "mail",],
+ "depends": ["document_page", "mail"],
"data": [
"data/email_template.xml",
"views/document_page_approval.xml",
diff --git a/document_page_approval/hooks.py b/document_page_approval/hooks.py
index 0fa1e3b1..d0b780a2 100644
--- a/document_page_approval/hooks.py
+++ b/document_page_approval/hooks.py
@@ -22,4 +22,4 @@ def post_init_hook(cr, registry): # pragma: no cover
def uninstall_hook(cr, registry): # pragma: no cover
# Remove unapproved pages
_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'")
diff --git a/document_page_approval/models/document_page.py b/document_page_approval/models/document_page.py
index 3f9e21fb..a4528f0e 100644
--- a/document_page_approval/models/document_page.py
+++ b/document_page_approval/models/document_page.py
@@ -13,7 +13,7 @@ class DocumentPage(models.Model):
_inherit = "document.page"
history_ids = fields.One2many(
- order="approved_date DESC", domain=[("state", "=", "approved")],
+ order="approved_date DESC", domain=[("state", "=", "approved")]
)
approved_date = fields.Datetime(
@@ -65,10 +65,9 @@ class DocumentPage(models.Model):
)
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")
def _compute_is_approval_required(self):
"""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
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."""
@@ -88,14 +86,12 @@ class DocumentPage(models.Model):
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()
@@ -114,7 +110,6 @@ class DocumentPage(models.Model):
# to approve, user must belong to any of the approver groups
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:
@@ -123,7 +118,6 @@ class DocumentPage(models.Model):
)
rec.has_changes_pending_approval = changes > 0
- @api.multi
def _compute_user_has_drafts(self):
history = self.env["document.page.history"]
for rec in self:
@@ -132,12 +126,10 @@ class DocumentPage(models.Model):
)
rec.user_has_drafts = changes > 0
- @api.multi
def _create_history(self, vals):
res = super(DocumentPage, self)._create_history(vals)
res.action_to_approve()
- @api.multi
def action_changes_pending_approval(self):
self.ensure_one()
action = self.env.ref("document_page_approval.action_change_requests")
diff --git a/document_page_approval/models/document_page_history.py b/document_page_approval/models/document_page_history.py
index 2acf6932..4d70f86f 100644
--- a/document_page_approval/models/document_page_history.py
+++ b/document_page_approval/models/document_page_history.py
@@ -1,7 +1,7 @@
# Copyright (C) 2013 Savoir-faire Linux ().
# 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.tools.translate import _
@@ -24,21 +24,20 @@ class DocumentPageHistory(models.Model):
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(
- 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_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):
"""Set a change request as draft"""
for rec in self:
@@ -53,7 +52,6 @@ class DocumentPageHistory(models.Model):
)
rec.write({"state": "draft"})
- @api.multi
def action_to_approve(self):
"""Set a change request as to approve"""
template = self.env.ref(
@@ -85,7 +83,6 @@ class DocumentPageHistory(models.Model):
# auto-approve if approval is not required
rec.action_approve()
- @api.multi
def action_approve(self):
"""Set a change request as approved."""
for rec in self:
@@ -123,7 +120,6 @@ class DocumentPageHistory(models.Model):
body=_("New version of the document %s approved.") % (rec.page_id.name),
)
- @api.multi
def action_cancel(self):
"""Set a change request as cancelled."""
self.write({"state": "cancelled"})
@@ -134,19 +130,16 @@ class DocumentPageHistory(models.Model):
% (rec.display_name, self.env.user.name),
)
- @api.multi
def action_cancel_and_draft(self):
"""Set a change request as draft, cancelling it first"""
self.action_cancel()
self.action_draft()
- @api.multi
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 _compute_page_url(self):
"""Compute the page url."""
for page in self:
@@ -157,10 +150,9 @@ class DocumentPageHistory(models.Model):
)
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)
- @api.multi
def _compute_diff(self):
"""Shows a diff between this version and the previous version"""
history = self.env["document.page.history"]
diff --git a/document_page_approval/readme/CONTRIBUTORS.rst b/document_page_approval/readme/CONTRIBUTORS.rst
index 0e72ccdc..f2a999f9 100644
--- a/document_page_approval/readme/CONTRIBUTORS.rst
+++ b/document_page_approval/readme/CONTRIBUTORS.rst
@@ -4,3 +4,7 @@
* Maxime Chambreuil
* Iván Todorovich
* Victor M.M. Torres
+
+* `Guadaltech `_:
+
+ * Fernando La Chica
diff --git a/document_page_approval/static/description/index.html b/document_page_approval/static/description/index.html
index 4bdeca25..38c2176c 100644
--- a/document_page_approval/static/description/index.html
+++ b/document_page_approval/static/description/index.html
@@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-
+
This module adds a workflow to approve page modifications
and show the approved version by default.
Table of contents
@@ -411,7 +411,7 @@ page history to review.
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.
Do not contact contributors directly about support or help with technical issues.
@@ -440,7 +440,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
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.
-
This module is part of the OCA/knowledge project on GitHub.
+
This module is part of the OCA/knowledge project on GitHub.