10 changed files with 360 additions and 101 deletions
-
20help_popup/README.rst
-
24help_popup/__openerp__.py
-
43help_popup/demo/help.xml
-
142help_popup/model.py
-
46help_popup/report/all.xml
-
32help_popup/report/help.xml
-
7help_popup/report/report.xml
-
26help_popup/static/src/js/popup_help.js
-
5help_popup/static/src/xml/popup_help.xml
-
72help_popup/views/action_view.xml
@ -1,35 +1,127 @@ |
|||
# coding: utf-8 |
|||
############################################################################## |
|||
# |
|||
# Odoo, Open Source Management Solution |
|||
# Copyright (C) 2015-TODAY Akretion (<http://www.akretion.com>). |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
|
|||
from openerp import models, fields |
|||
# © 2015 David BEAL @ Akretion <david.beal@akretion.com> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from openerp import _, api, models, fields |
|||
|
|||
class IrActionsActwindow(models.Model): |
|||
_inherit = 'ir.actions.act_window' |
|||
|
|||
class ErpHelp(models.AbstractModel): |
|||
_name = 'erp.help' |
|||
|
|||
enduser_help = fields.Html( |
|||
string="End User Help", |
|||
help="Use this field to add custom content for documentation purpose\n" |
|||
"mainly by power users ") |
|||
advanced_help = fields.Text( |
|||
string="Advanced Help", |
|||
string="Advanced Help", groups='base.group_no_one', |
|||
help="Use this field to add custom content for documentation purpose\n" |
|||
"mainly by developers") |
|||
"mainly by developers or consultants") |
|||
|
|||
|
|||
class IrModel(models.Model): |
|||
_inherit = ['ir.model', 'erp.help'] |
|||
_name = 'ir.model' |
|||
|
|||
|
|||
class IrActionsActwindow(models.Model): |
|||
_inherit = ['ir.actions.act_window', 'erp.help'] |
|||
_name = 'ir.actions.act_window' |
|||
_rpt_menu = False |
|||
|
|||
enduser_help_model = fields.Html( |
|||
string='Enduser Help from Model', store="True", |
|||
compute='_compute_model_help', inverse='_inverse_model_help', |
|||
help="") |
|||
advanced_help_model = fields.Text( |
|||
string='Advanced Help from model', store="True", |
|||
compute='_compute_model_help', inverse='_inverse_model_help', |
|||
help="") |
|||
action_help = fields.Boolean(string="Display Action Help") |
|||
help_has_content = fields.Boolean( |
|||
string="Content in help", compute='_compute_contains_help', |
|||
help="One of the help has content") |
|||
|
|||
@api.one |
|||
@api.depends('enduser_help', 'advanced_help', |
|||
'enduser_help_model', 'advanced_help_model') |
|||
def _compute_contains_help(self): |
|||
if (self.enduser_help or self.enduser_help_model or |
|||
self.advanced_help or self.advanced_help_model): |
|||
self.help_has_content = True |
|||
else: |
|||
self.help_has_content = False |
|||
|
|||
@api.multi |
|||
def _compute_model_help(self): |
|||
for rec in self: |
|||
model = rec.env['ir.model'].search([('model', '=', rec.res_model)]) |
|||
rec.enduser_help_model = model.enduser_help |
|||
rec.advanced_help_model = model.advanced_help |
|||
|
|||
def _inverse_model_help(self): |
|||
for rec in self: |
|||
model = rec.env['ir.model'].search([('model', '=', rec.res_model)]) |
|||
model.enduser_help = rec.enduser_help_model |
|||
model.advanced_help = rec.advanced_help_model |
|||
|
|||
@api.multi |
|||
def open_help_popup(self): |
|||
""" Open in a new tab instead of in popup""" |
|||
self.ensure_one() |
|||
return { |
|||
'name': _('Open help for this action'), |
|||
'type': 'ir.actions.act_url', |
|||
'url': 'report/html/help_popup.tpl_help/%s' % self.id, |
|||
'target': 'new', |
|||
} |
|||
|
|||
@api.model |
|||
def get_help_actions(self): |
|||
""" called by the template""" |
|||
self._rpt_menu = self.get_main_menu() |
|||
menu_names = self.get_menu_names(self._rpt_menu) |
|||
actions = self.search([ |
|||
('id', 'in', menu_names.keys()), |
|||
'|', '|', '|', |
|||
('enduser_help', '!=', False), |
|||
('enduser_help_model', '!=', False), |
|||
('advanced_help', '!=', False), |
|||
('advanced_help_model', '!=', False), |
|||
]) |
|||
return actions |
|||
|
|||
@api.model |
|||
def get_main_menu(self): |
|||
self._rpt_menu = False |
|||
ir_vals = self.env['ir.values'].search([ |
|||
('key2', '=', 'tree_but_open'), |
|||
('key', '=', 'action'), |
|||
('res_id', '>', 0), |
|||
('value', '=', 'ir.actions.act_window,%s' % self.id), |
|||
]) |
|||
if ir_vals: |
|||
# we only keep the first menu beacause we have no info on menu_id |
|||
self._rpt_menu = self.env['ir.ui.menu'].browse(ir_vals[0].res_id) |
|||
while self._rpt_menu.parent_id: |
|||
self._rpt_menu = self._rpt_menu.parent_id |
|||
return self._rpt_menu |
|||
|
|||
@api.model |
|||
def get_menu_names(self, main_menu): |
|||
""" @return dict {action_id: 'menu name'} """ |
|||
menus = self.env['ir.ui.menu'].search( |
|||
[('id', 'child_of', main_menu.id)]) |
|||
ir_vals = self.env['ir.values'].search([ |
|||
('key2', '=', 'tree_but_open'), |
|||
('key', '=', 'action'), |
|||
('res_id', 'in', menus.ids), |
|||
('value', 'like', 'ir.actions.act_window,%'), |
|||
]) |
|||
map_menu = {x.id: x.name for x in menus} |
|||
return {int(x.value[22:]): map_menu[x.res_id] for x in ir_vals} |
|||
|
|||
def _anchorize(self, string): |
|||
""" called by template """ |
|||
for char in ["'", '"', ' ']: |
|||
string = string.replace(char, '-') |
|||
return string |
@ -0,0 +1,46 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
|
|||
<openerp> |
|||
<data noupdate="1"> |
|||
|
|||
<template id="all_help"> |
|||
|
|||
<t t-call="report.html_container"> |
|||
<t t-call="report.internal_layout"> |
|||
|
|||
|
|||
<t t-foreach="docs" t-as="o"> |
|||
|
|||
<div class="page"> |
|||
<t t-set="actions" t-value="o.get_help_actions()"/> |
|||
<h2 class="text-center" t-if="o._rpt_menu" t-raw="o._rpt_menu.name"/> |
|||
<ul> |
|||
<t t-foreach="actions" t-as="act"> |
|||
<li> |
|||
<a t-attf-href="#-{{ o._anchorize(act.name) }}" t-raw='act.name'/> |
|||
</li> |
|||
</t> |
|||
</ul> |
|||
<t t-foreach="actions" t-as="act"> |
|||
<h2 t-attf-id="-{{ o._anchorize(act.name) }}" t-raw='act.name'/> |
|||
<div class="bg-warning" t-if="act.enduser_help" t-raw="act.enduser_help"/> |
|||
<div class="bg-warning" t-if="act.enduser_help_model" t-raw="act.enduser_help_model"/> |
|||
<hr width="70%"/> |
|||
<div t-if="act.advanced_help" t-raw="act.advanced_help"/> |
|||
<div t-if="act.advanced_help_model" t-raw="act.advanced_help_model"/> |
|||
</t> |
|||
<hr width="70%"/> |
|||
|
|||
</div> |
|||
|
|||
<!--end foreach--> |
|||
</t> |
|||
|
|||
</t> |
|||
</t> |
|||
|
|||
</template> |
|||
|
|||
|
|||
</data> |
|||
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue