mirror of
https://github.com/OCA/knowledge.git
synced 2025-12-19 03:42:19 -06:00
[IMP] document_page_approval: black, isort
This commit is contained in:
committed by
Bhavesh Heliconia
parent
e1727575df
commit
8d8c8ac32a
@@ -2,77 +2,74 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
|
||||
from odoo import api, fields, models
|
||||
from ast import literal_eval
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class DocumentPage(models.Model):
|
||||
"""Useful to know the state of a document."""
|
||||
|
||||
_inherit = 'document.page'
|
||||
_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(
|
||||
'Approved Date',
|
||||
related='history_head.approved_date',
|
||||
"Approved Date",
|
||||
related="history_head.approved_date",
|
||||
store=True,
|
||||
index=True,
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
approved_uid = fields.Many2one(
|
||||
'res.users',
|
||||
'Approved by',
|
||||
related='history_head.approved_uid',
|
||||
"res.users",
|
||||
"Approved by",
|
||||
related="history_head.approved_uid",
|
||||
store=True,
|
||||
index=True,
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
approval_required = fields.Boolean(
|
||||
'Require approval',
|
||||
help='Require approval for changes on this page or its child pages.',
|
||||
"Require approval",
|
||||
help="Require approval for changes on this page or its child pages.",
|
||||
)
|
||||
|
||||
approver_gid = fields.Many2one(
|
||||
"res.groups",
|
||||
"Approver group",
|
||||
help='Users must also belong to the Approvers 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',
|
||||
"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'
|
||||
)
|
||||
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',
|
||||
"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'
|
||||
compute="_compute_has_changes_pending_approval",
|
||||
string="Has changes pending approval",
|
||||
)
|
||||
|
||||
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):
|
||||
"""Check if the document required approval based on his parents."""
|
||||
for page in self:
|
||||
@@ -82,7 +79,7 @@ class DocumentPage(models.Model):
|
||||
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):
|
||||
"""Compute the approver groups based on his parents."""
|
||||
for page in self:
|
||||
@@ -92,7 +89,7 @@ class DocumentPage(models.Model):
|
||||
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):
|
||||
"""Check if the current user can approve changes to this page."""
|
||||
for rec in self:
|
||||
@@ -106,11 +103,10 @@ class DocumentPage(models.Model):
|
||||
if not self.is_approval_required:
|
||||
return True
|
||||
# if user belongs to 'Knowledge / Manager', he can approve anything
|
||||
if user.has_group('document_page.group_document_manager'):
|
||||
if user.has_group("document_page.group_document_manager"):
|
||||
return True
|
||||
# to approve, user must have approver rights
|
||||
if not user.has_group(
|
||||
'document_page_approval.group_document_approver_user'):
|
||||
if not user.has_group("document_page_approval.group_document_approver_user"):
|
||||
return False
|
||||
# if there aren't any approver_groups_defined, user can approve
|
||||
if not self.approver_group_ids:
|
||||
@@ -120,21 +116,21 @@ class DocumentPage(models.Model):
|
||||
|
||||
@api.multi
|
||||
def _compute_has_changes_pending_approval(self):
|
||||
history = self.env['document.page.history']
|
||||
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)
|
||||
changes = history.search_count(
|
||||
[("page_id", "=", rec.id), ("state", "=", "to approve")]
|
||||
)
|
||||
rec.has_changes_pending_approval = changes > 0
|
||||
|
||||
@api.multi
|
||||
def _compute_user_has_drafts(self):
|
||||
history = self.env['document.page.history']
|
||||
history = self.env["document.page.history"]
|
||||
for rec in self:
|
||||
changes = history.search_count([
|
||||
('page_id', '=', rec.id),
|
||||
('state', '=', 'draft')])
|
||||
rec.user_has_drafts = (changes > 0)
|
||||
changes = history.search_count(
|
||||
[("page_id", "=", rec.id), ("state", "=", "draft")]
|
||||
)
|
||||
rec.user_has_drafts = changes > 0
|
||||
|
||||
@api.multi
|
||||
def _create_history(self, vals):
|
||||
@@ -144,10 +140,10 @@ class DocumentPage(models.Model):
|
||||
@api.multi
|
||||
def action_changes_pending_approval(self):
|
||||
self.ensure_one()
|
||||
action = self.env.ref('document_page_approval.action_change_requests')
|
||||
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
|
||||
context = literal_eval(action["context"])
|
||||
context["search_default_page_id"] = self.id
|
||||
context["default_page_id"] = self.id
|
||||
action["context"] = context
|
||||
return action
|
||||
|
||||
Reference in New Issue
Block a user