mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-18 21:16:31 -06:00
add a need approval field and hide the workflow when no approval needed
(../7.0pageapproval/ rev 7)
This commit is contained in:
parent
5a2fc56765
commit
19e016bf75
@ -23,13 +23,6 @@ from datetime import *
|
||||
|
||||
class document_page_history_wkfl(orm.Model):
|
||||
_inherit = 'document.page.history'
|
||||
_columns = {
|
||||
'state': fields.selection([
|
||||
('draft','Draft'),
|
||||
('approved','Approved')], 'Status', readonly=True),
|
||||
'approved_date': fields.datetime("Approved Date"),
|
||||
'approved_uid': fields.many2one('res.users', "Approved By"),
|
||||
}
|
||||
|
||||
def page_approval_draft(self, cr, uid, ids):
|
||||
self.write(cr, uid, ids, { 'state' : 'draft' })
|
||||
@ -42,6 +35,21 @@ class document_page_history_wkfl(orm.Model):
|
||||
})
|
||||
return True
|
||||
|
||||
def _is_parent_approval_required(self, cr, uid, ids, name, args, context=None):
|
||||
res = {}
|
||||
for page in self.browse(cr, uid, ids, context=context):
|
||||
res[page.id] = page.page_id.is_parent_approval_required
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'state': fields.selection([
|
||||
('draft','Draft'),
|
||||
('approved','Approved')], 'Status', readonly=True),
|
||||
'approved_date': fields.datetime("Approved Date"),
|
||||
'approved_uid': fields.many2one('res.users', "Approved By"),
|
||||
'is_parent_approval_required': fields.function(_is_parent_approval_required, string="parent approval", type='boolean'),
|
||||
}
|
||||
|
||||
|
||||
class document_page_approval(orm.Model):
|
||||
_inherit = 'document.page'
|
||||
@ -53,33 +61,58 @@ class document_page_approval(orm.Model):
|
||||
content = self._get_page_index(cr, uid, page, link=False)
|
||||
else:
|
||||
history = self.pool.get('document.page.history')
|
||||
if self.is_approval_required(page):
|
||||
history_ids = history.search(cr, uid,[('page_id', '=', page.id), ('state', '=', 'approved')], limit=1, order='create_date DESC')
|
||||
for h in history.browse(cr, uid, history_ids):
|
||||
content = h.content
|
||||
else:
|
||||
content = page.content
|
||||
res[page.id] = content
|
||||
return res
|
||||
|
||||
def _get_approved_date(self, cr, uid, ids, name, args, context=None):
|
||||
res = {}
|
||||
for i in ids:
|
||||
for page in self.browse(cr, uid, ids, context=context):
|
||||
if self.is_approval_required(page):
|
||||
history = self.pool.get('document.page.history')
|
||||
history_ids = history.search(cr, uid,[('page_id', '=', i), ('state', '=', 'approved')], limit=1, order='create_date DESC')
|
||||
history_ids = history.search(cr, uid,[('page_id', '=', page.id), ('state', '=', 'approved')], limit=1, order='create_date DESC')
|
||||
approved_date = False
|
||||
for h in history.browse(cr, uid, history_ids):
|
||||
approved_date = h.approved_date
|
||||
res[i] = approved_date
|
||||
res[page.id] = approved_date
|
||||
else:
|
||||
res[page.id] = ""
|
||||
|
||||
return res
|
||||
|
||||
def _get_approved_uid(self, cr, uid, ids, name, args, context=None):
|
||||
res = {}
|
||||
for i in ids:
|
||||
for page in self.browse(cr, uid, ids, context=context):
|
||||
if self.is_approval_required(page):
|
||||
history = self.pool.get('document.page.history')
|
||||
history_ids = history.search(cr, uid,[('page_id', '=', i), ('state', '=', 'approved')], limit=1, order='create_date DESC')
|
||||
history_ids = history.search(cr, uid,[('page_id', '=', page.id), ('state', '=', 'approved')], limit=1, order='create_date DESC')
|
||||
approved_uid = False
|
||||
for h in history.browse(cr, uid, history_ids):
|
||||
approved_uid = h.approved_uid.id
|
||||
res[i] = approved_uid
|
||||
res[page.id] = approved_uid
|
||||
else:
|
||||
res[page.id] = ""
|
||||
|
||||
return res
|
||||
|
||||
def _is_parent_approval_required(self, cr, uid, ids, name, args, context=None):
|
||||
res = {}
|
||||
for page in self.browse(cr, uid, ids, context=context):
|
||||
res[page.id]= self.is_approval_required(page)
|
||||
|
||||
return res
|
||||
|
||||
def is_approval_required(self, page):
|
||||
if page:
|
||||
res = page.approval_required
|
||||
res = res or self.is_approval_required(page.parent_id)
|
||||
else:
|
||||
res=False
|
||||
|
||||
return res
|
||||
|
||||
@ -87,5 +120,8 @@ class document_page_approval(orm.Model):
|
||||
'display_content': fields.function(_get_display_content, string='Displayed Content', type='text'),
|
||||
'approved_date': fields.function(_get_approved_date, string="Approved Date", type='datetime'),
|
||||
'approved_uid': fields.function(_get_approved_uid, string="Approved By", type='many2one', obj='res.users'),
|
||||
'approval_required': fields.boolean("Require approval"),
|
||||
'is_parent_approval_required': fields.function(_is_parent_approval_required, string="parent approval", type='boolean'),
|
||||
'approver_gid': fields.many2one("res.groups", "Approver group"),
|
||||
}
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
@ -7,9 +7,10 @@
|
||||
<field name="inherit_id" ref="document_page.wiki_history_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//form/label[@for='page_id']" position="before">
|
||||
<header>
|
||||
<header attrs="{'invisible':[('is_parent_approval_required','=',False)]}">
|
||||
<button name="page_approval_approve" string="Approve" states="draft" />
|
||||
<field name="state" widget="statusbar" statusbar_visible="draft,approved"/>
|
||||
<field name="is_parent_approval_required" invisible="1"/>
|
||||
</header>
|
||||
</xpath>
|
||||
</field>
|
||||
@ -24,6 +25,10 @@
|
||||
<field name="approved_date" class="oe_view_only"/>
|
||||
<field name="approved_uid" class="oe_view_only"/>
|
||||
</field>
|
||||
<field name="parent_id" position="after">
|
||||
<field name="approval_required" attrs="{'invisible':[('type','=','content')]}"/>
|
||||
<field name="approver_gid" attrs="{'invisible':[('type','=','content')], 'required':[('approval_required','=', 'true')]}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@ -33,7 +38,8 @@
|
||||
<field name="inherit_id" ref="document_page.view_wiki_history_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="page_id" position="after">
|
||||
<field name="state"/>
|
||||
<field name="state" attrs="{'invisible':[('is_parent_approval_required','=',False)]}"/>
|
||||
<field name="is_parent_approval_required" invisible="1"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
Loading…
Reference in New Issue
Block a user