mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-22 20:12:04 -06:00
[document_page_approval] Rename classes and files to match model names, and removed workflow engine.
This commit is contained in:
parent
6b80913167
commit
bb90405d48
@ -1 +1 @@
|
||||
from . import document_page_approval, document_page_history_workflow
|
||||
from . import document_page, document_page_history
|
||||
|
@ -6,7 +6,7 @@ from odoo import api, fields, models
|
||||
from ast import literal_eval
|
||||
|
||||
|
||||
class DocumentPageApproval(models.Model):
|
||||
class DocumentPage(models.Model):
|
||||
"""Useful to know the state of a document."""
|
||||
|
||||
_inherit = 'document.page'
|
||||
@ -121,8 +121,8 @@ class DocumentPageApproval(models.Model):
|
||||
|
||||
@api.multi
|
||||
def _create_history(self, vals):
|
||||
res = super(DocumentPageApproval, self)._create_history(vals)
|
||||
res.document_page_auto_confirm()
|
||||
res = super(DocumentPage, self)._create_history(vals)
|
||||
res.action_to_approve()
|
||||
|
||||
@api.multi
|
||||
def action_changes_pending_approval(self):
|
@ -1,14 +1,12 @@
|
||||
# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from datetime import datetime
|
||||
from odoo.tools.translate import _
|
||||
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
|
||||
from odoo import api, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class DocumentPageHistoryWorkflow(models.Model):
|
||||
class DocumentPageHistory(models.Model):
|
||||
"""Useful to manage edition's workflow on a document."""
|
||||
|
||||
_name = 'document.page.history'
|
||||
@ -20,8 +18,8 @@ class DocumentPageHistoryWorkflow(models.Model):
|
||||
('approved', 'Approved'),
|
||||
('cancelled', 'Cancelled')],
|
||||
'Status',
|
||||
default='draft',
|
||||
readonly=True,
|
||||
default='draft'
|
||||
)
|
||||
|
||||
approved_date = fields.Datetime(
|
||||
@ -52,56 +50,67 @@ class DocumentPageHistoryWorkflow(models.Model):
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def page_approval_draft(self):
|
||||
def action_draft(self):
|
||||
"""Set a change request as draft"""
|
||||
if self.filtered(lambda r: r.state not in [
|
||||
'cancelled', 'approved']):
|
||||
raise UserError(_("It's not cancelled or approved"))
|
||||
if self.filtered(lambda r:
|
||||
r.state == 'approved' and not self.am_i_approver):
|
||||
raise UserError(_("You are not an appover to reset to draft"))
|
||||
self.write({'state': 'draft'})
|
||||
for rec in self:
|
||||
if not rec.state == 'cancelled':
|
||||
raise UserError(
|
||||
_('You need to cancel it before reopening.'))
|
||||
if not (rec.am_i_owner or rec.am_i_approver):
|
||||
raise UserError(
|
||||
_('You are not authorized to do this.\r\n'
|
||||
'Only owners or approvers can reopen Change Requests.'))
|
||||
rec.write({'state': 'draft'})
|
||||
|
||||
@api.multi
|
||||
def document_page_auto_confirm(self):
|
||||
"""Automatic Transitions for change requests created directly from
|
||||
documents
|
||||
"""
|
||||
if self.filtered(lambda r: r.state != 'draft'):
|
||||
raise UserError(_("It's not in draft state"))
|
||||
to_approve = self.filtered(lambda r: r.is_approval_required)
|
||||
to_approve.write({'state': 'to approve'})
|
||||
approved = (self - to_approve)
|
||||
approved.write({'state': 'approved'})
|
||||
approved.mapped('page_id')._compute_history_head()
|
||||
|
||||
@api.multi
|
||||
def page_approval_to_approve(self):
|
||||
def action_to_approve(self):
|
||||
"""Set a change request as to approve"""
|
||||
self.write({'state': 'to approve'})
|
||||
template = self.env.ref(
|
||||
'document_page_approval.email_template_new_draft_need_approval')
|
||||
approver_gid = self.env.ref(
|
||||
'document_page_approval.group_document_approver_user')
|
||||
for rec in self:
|
||||
if rec.state != 'draft':
|
||||
raise UserError(
|
||||
_("Can't approve pages in '%s' state.") % rec.state)
|
||||
if not (rec.am_i_owner or rec.am_i_approver):
|
||||
raise UserError(
|
||||
_('You are not authorized to do this.\r\n'
|
||||
'Only owners or approvers can request approval.'))
|
||||
# request approval
|
||||
if rec.is_approval_required:
|
||||
rec.write({'state': 'to approve'})
|
||||
guids = [g.id for g in rec.page_id.approver_group_ids]
|
||||
users = self.env['res.users'].search([
|
||||
('groups_id', 'in', guids),
|
||||
('groups_id', 'in', approver_gid.id)])
|
||||
rec.message_subscribe_users([u.id for u in users])
|
||||
rec.message_post_with_template(template.id)
|
||||
else:
|
||||
# auto-approve if approval is not required
|
||||
rec.action_approve()
|
||||
|
||||
@api.multi
|
||||
def page_approval_approved(self):
|
||||
def action_approve(self):
|
||||
"""Set a change request as approved."""
|
||||
self.write({
|
||||
'state': 'approved',
|
||||
'approved_date': datetime.now().strftime(
|
||||
DEFAULT_SERVER_DATETIME_FORMAT),
|
||||
'approved_uid': self.env.uid
|
||||
})
|
||||
for rec in self:
|
||||
if rec.state not in ['draft', 'to approve']:
|
||||
raise UserError(
|
||||
_("Can't approve page in '%s' state.") % rec.state)
|
||||
if not rec.am_i_approver:
|
||||
raise UserError(_(
|
||||
'You are not authorized to do this.\r\n'
|
||||
'Only approvers with these groups can approve this: '
|
||||
) % ', '.join(
|
||||
[g.display_name
|
||||
for g in rec.page_id.approver_group_ids])
|
||||
)
|
||||
# Update state
|
||||
rec.write({
|
||||
'state': 'approved',
|
||||
'approved_date': fields.datetime.now(),
|
||||
'approved_uid': self.env.uid,
|
||||
})
|
||||
# Trigger computed field update
|
||||
rec.page_id._compute_history_head()
|
||||
# Notify state change
|
||||
@ -120,7 +129,7 @@ class DocumentPageHistoryWorkflow(models.Model):
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def page_approval_cancelled(self):
|
||||
def action_cancel(self):
|
||||
"""Set a change request as cancelled."""
|
||||
self.write({'state': 'cancelled'})
|
||||
for rec in self:
|
@ -47,7 +47,7 @@ class TestDocumentPageApproval(common.TransactionCase):
|
||||
self.assertTrue(chreq.am_i_approver)
|
||||
|
||||
# approve
|
||||
chreq.page_approval_approved()
|
||||
chreq.action_approve()
|
||||
self.assertEqual(chreq.state, 'approved')
|
||||
self.assertEqual(chreq.content, page.content)
|
||||
|
||||
@ -58,7 +58,7 @@ class TestDocumentPageApproval(common.TransactionCase):
|
||||
('page_id', '=', page.id),
|
||||
('state', '!=', 'approved')
|
||||
])[0]
|
||||
chreq.page_approval_approved()
|
||||
chreq.action_approve()
|
||||
self.assertEqual(page.content, 'New content')
|
||||
|
||||
def test_change_request_auto_approve(self):
|
||||
@ -74,7 +74,7 @@ class TestDocumentPageApproval(common.TransactionCase):
|
||||
self.history_obj.search([
|
||||
('page_id', '=', page.id),
|
||||
('state', '!=', 'approved')
|
||||
]).page_approval_approved()
|
||||
]).action_approve()
|
||||
|
||||
# new change request from scrath
|
||||
chreq = self.history_obj.create({
|
||||
@ -88,25 +88,25 @@ class TestDocumentPageApproval(common.TransactionCase):
|
||||
self.assertNotEqual(page.approved_date, chreq.approved_date)
|
||||
self.assertNotEqual(page.approved_uid, chreq.approved_uid)
|
||||
|
||||
chreq.page_approval_to_approve()
|
||||
chreq.action_to_approve()
|
||||
self.assertEqual(chreq.state, 'to approve')
|
||||
self.assertNotEqual(page.content, chreq.content)
|
||||
self.assertNotEqual(page.approved_date, chreq.approved_date)
|
||||
self.assertNotEqual(page.approved_uid, chreq.approved_uid)
|
||||
|
||||
chreq.page_approval_cancelled()
|
||||
chreq.action_cancel()
|
||||
self.assertEqual(chreq.state, 'cancelled')
|
||||
self.assertNotEqual(page.content, chreq.content)
|
||||
self.assertNotEqual(page.approved_date, chreq.approved_date)
|
||||
self.assertNotEqual(page.approved_uid, chreq.approved_uid)
|
||||
|
||||
chreq.page_approval_draft()
|
||||
chreq.action_draft()
|
||||
self.assertEqual(chreq.state, 'draft')
|
||||
self.assertNotEqual(page.content, chreq.content)
|
||||
self.assertNotEqual(page.approved_date, chreq.approved_date)
|
||||
self.assertNotEqual(page.approved_uid, chreq.approved_uid)
|
||||
|
||||
chreq.page_approval_approved()
|
||||
chreq.action_approve()
|
||||
self.assertEqual(chreq.state, 'approved')
|
||||
self.assertEqual(page.content, chreq.content)
|
||||
self.assertEqual(page.approved_date, chreq.approved_date)
|
||||
|
@ -10,19 +10,19 @@
|
||||
<sheet position="before">
|
||||
<header>
|
||||
<!-- draft -> to approve -->
|
||||
<button name="page_approval_to_approve" type="object" string="Send to Review" state="draft" class="oe_highlight"
|
||||
<button name="action_to_approve" type="object" string="Send to Review" class="oe_highlight"
|
||||
attrs="{'invisible':['|','|',('is_approval_required','=',False),('am_i_owner','=',False),('state', 'not in', ['draft'])]}"/>
|
||||
<!-- approve if i am approver -->
|
||||
<button name="page_approval_approved" type="object" string="Approve" state="to aprrove" class="oe_highlight"
|
||||
<button name="action_approve" type="object" string="Approve" class="oe_highlight"
|
||||
attrs="{'invisible':['|','|',('is_approval_required','=',False),('am_i_approver','=',False),('state','not in',['draft','to approve'])]}"/>
|
||||
<!-- approve if it's not required and i am owner -->
|
||||
<button name="page_approval_approved" type="object" string="Approve" class="oe_highlight"
|
||||
<button name="action_approve" type="object" string="Approve" class="oe_highlight"
|
||||
attrs="{'invisible':['|','|',('is_approval_required','=',True),('am_i_owner','=',False),('state','not in',['draft', 'to approve'])]}"/>
|
||||
<!-- cancel if i am owner or approver -->
|
||||
<button name="page_approval_cancelled" type="object" string="Cancel"
|
||||
<button name="action_cancel" type="object" string="Cancel"
|
||||
attrs="{'invisible':['|','&',('am_i_owner','=',False),('am_i_approver','=',False),('state','not in',['draft','to approve'])]}"/>
|
||||
<!-- reopen if i am owner or approver -->
|
||||
<button name="page_approval_draft" type="object" string="Back to draft" state="cancelled"
|
||||
<button name="action_draft" type="object" string="Back to draft"
|
||||
attrs="{'invisible':['|','&',('am_i_owner','=',False),('am_i_approver','=',False),('state','not in',['cancelled'])]}"/>
|
||||
<field name="am_i_owner" invisible="1"/>
|
||||
<field name="am_i_approver" invisible="1"/>
|
||||
|
Loading…
Reference in New Issue
Block a user