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:
flachica
2020-07-04 19:13:10 +02:00
committed by FernandoRomera
parent bc79903d9e
commit 32b684c65f
8 changed files with 27 additions and 37 deletions

View File

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

View File

@@ -1,7 +1,7 @@
# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
# 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"]