mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-23 17:08:46 -06:00
[document_page_approval] Improve ux by adding user_has_drafts to document pages.
This commit is contained in:
parent
fc275f9c67
commit
e1e1a06bc4
@ -66,6 +66,11 @@ class DocumentPage(models.Model):
|
|||||||
string='Has changes pending approval'
|
string='Has changes pending approval'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
user_has_drafts = fields.Boolean(
|
||||||
|
compute='_compute_user_has_drafts',
|
||||||
|
string='User has drafts?',
|
||||||
|
)
|
||||||
|
|
||||||
@api.multi
|
@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):
|
def _compute_is_approval_required(self):
|
||||||
@ -119,6 +124,15 @@ class DocumentPage(models.Model):
|
|||||||
('state', '=', 'to approve')])
|
('state', '=', 'to approve')])
|
||||||
rec.has_changes_pending_approval = (changes > 0)
|
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:
|
||||||
|
changes = history.search_count([
|
||||||
|
('page_id', '=', rec.id),
|
||||||
|
('state', '=', 'draft')])
|
||||||
|
rec.user_has_drafts = (changes > 0)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _create_history(self, vals):
|
def _create_history(self, vals):
|
||||||
res = super(DocumentPage, self)._create_history(vals)
|
res = super(DocumentPage, self)._create_history(vals)
|
||||||
|
@ -80,15 +80,21 @@
|
|||||||
attrs="{'invisible': [('is_approval_required','=',False)]}">
|
attrs="{'invisible': [('is_approval_required','=',False)]}">
|
||||||
This document requires approval. If edited, you will create a new <b>Change Request</b>.
|
This document requires approval. If edited, you will create a new <b>Change Request</b>.
|
||||||
</div>
|
</div>
|
||||||
|
<div class="alert alert-warning oe_edit_only" role="alert" style="margin-bottom:0px;"
|
||||||
|
attrs="{'invisible': [('user_has_drafts','=',False)]}">
|
||||||
|
<b>You already have a Draft Change Request for this page.</b>
|
||||||
|
It is highly recommended that you edit that one instead of creating a new one.
|
||||||
|
</div>
|
||||||
<field name="is_approval_required" invisible="1"/>
|
<field name="is_approval_required" invisible="1"/>
|
||||||
<field name="has_changes_pending_approval" invisible="1"/>
|
<field name="has_changes_pending_approval" invisible="1"/>
|
||||||
|
<field name="user_has_drafts" invisible="1"/>
|
||||||
</sheet>
|
</sheet>
|
||||||
|
|
||||||
<field name="type" position="before">
|
<field name="type" position="before">
|
||||||
<div class="oe_button_box" name="button_box">
|
<div class="oe_button_box" name="button_box">
|
||||||
<button class="oe_stat_button" name="action_changes_pending_approval"
|
<button class="oe_stat_button" name="action_changes_pending_approval"
|
||||||
string="Change Requests" type="object"
|
string="Change Requests" type="object"
|
||||||
attrs="{'invisible':[('has_changes_pending_approval','=',False)]}" icon="fa-edit"/>
|
attrs="{'invisible':[('has_changes_pending_approval','=',False),('user_has_drafts','=',False)]}" icon="fa-edit"/>
|
||||||
</div>
|
</div>
|
||||||
</field>
|
</field>
|
||||||
|
|
||||||
@ -192,7 +198,7 @@
|
|||||||
<field name="res_model">document.page.history</field>
|
<field name="res_model">document.page.history</field>
|
||||||
<field name="view_type">form</field>
|
<field name="view_type">form</field>
|
||||||
<field name="view_mode">tree,form</field>
|
<field name="view_mode">tree,form</field>
|
||||||
<field name="context">{'search_default_state':'to approve'}</field>
|
<field name="context">{'search_default_draft': 1, 'search_default_pending': 1}</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<menuitem id="menu_page_change_requests"
|
<menuitem id="menu_page_change_requests"
|
||||||
|
Loading…
Reference in New Issue
Block a user