[MIG] document_page_approval: Migration to 11.0

This commit is contained in:
Gabriela Mogollon
2018-06-14 20:09:23 +00:00
committed by Bhavesh Heliconia
parent afc1bf0423
commit ffb2adb712
82 changed files with 2251 additions and 741 deletions

View File

@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
from . import document_page_approval, document_page_history_workflow

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
@@ -123,7 +122,7 @@ class DocumentPageApproval(models.Model):
@api.multi
def _create_history(self, vals):
res = super(DocumentPageApproval, self)._create_history(vals)
res.signal_workflow('document_page_auto_confirm')
res.document_page_auto_confirm()
@api.multi
def action_changes_pending_approval(self):

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
@@ -6,6 +5,7 @@ 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):
@@ -21,6 +21,7 @@ class DocumentPageHistoryWorkflow(models.Model):
('cancelled', 'Cancelled')],
'Status',
readonly=True,
default='draft'
)
approved_date = fields.Datetime(
@@ -42,7 +43,7 @@ class DocumentPageHistoryWorkflow(models.Model):
)
am_i_approver = fields.Boolean(
related='page_id.am_i_approver'
compute='_compute_am_i_approver'
)
page_url = fields.Text(
@@ -53,8 +54,27 @@ class DocumentPageHistoryWorkflow(models.Model):
@api.multi
def page_approval_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'})
@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):
"""Set a change request as to approve"""
@@ -117,11 +137,18 @@ class DocumentPageHistoryWorkflow(models.Model):
for rec in self:
rec.am_i_owner = (rec.create_uid == self.env.user)
@api.multi
def _compute_am_i_approver(self):
"""check if current user is a approver"""
for rec in self:
rec.am_i_approver = rec.page_id.can_user_approve_this_page(
self.env.user)
@api.multi
def _compute_page_url(self):
"""Compute the page url."""
for page in self:
base_url = self.env['ir.config_parameter'].get_param(
base_url = self.env['ir.config_parameter'].sudo().get_param(
'web.base.url',
default='http://localhost:8069'
)