diff --git a/help_popup/model.py b/help_popup/model.py index 227915a4..1bf54023 100644 --- a/help_popup/model.py +++ b/help_popup/model.py @@ -2,7 +2,11 @@ # © 2015 David BEAL @ Akretion # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from BeautifulSoup import BeautifulSoup as BSHTML +import inspect + from openerp import _, api, models, fields +from openerp.exceptions import Warning as UserError class ErpHelp(models.AbstractModel): @@ -17,6 +21,13 @@ class ErpHelp(models.AbstractModel): help="Use this field to add custom content for documentation purpose\n" "mainly by developers or consultants") + # @api.multi + # def write(self, vals): + # if not self._context.get('install_mode') and 'advanced_help' in vals: + # raise UserError(_("Advanced help field must only be updated " + # "by install mode (not with the user interface")) + # return super(ErpHelp, self).write(vals) + class IrModel(models.Model): _inherit = ['ir.model', 'erp.help'] @@ -64,6 +75,45 @@ class IrActionsActwindow(models.Model): model.enduser_help = rec.enduser_help_model model.advanced_help = rec.advanced_help_model + @api.multi + def write(self, vals): + if self._context.get('install_mode'): + module_name = self.module_being_update_or_insert() + for field in ['advanced_help']: + if field in vals: + self._update_help_field(vals, field, module_name) + return super(IrActionsActwindow, self).write(vals) + + @api.multi + def _update_help_field(self, vals, field, module_name): + new_val_field = u'%s' % ( + module_name, vals[field] or '', module_name) + original_val_field = vals[field] + vals[field] = new_val_field + if self[field]: + # we search this string in field: + # ... any content ... + tag = getattr( + BSHTML(self[field]), 'help_%s' % module_name) + if tag: + old_content = ''.join( + [unicode(x) for x in tag.contents if x]) or u'' + vals[field] = self[field].replace( + old_content, original_val_field) + else: + vals[field] = u'\n%s%s' % ( + self[field], new_val_field) + + @api.model + def module_being_update_or_insert(self): + for elm in inspect.stack(): + arg_values = inspect.getargvalues(elm[0]) + if 'locals' in arg_values.__dict__: + if arg_values.__dict__['locals'].get('module'): + module = arg_values.__dict__['locals'].get('module') + if module not in self.env.registry: + return arg_values.__dict__['locals'].get('module') + @api.multi def open_help_popup(self): """ Open in a new tab instead of in popup""" diff --git a/help_popup/report/help.xml b/help_popup/report/help.xml index e2aaa05f..03dcbf86 100644 --- a/help_popup/report/help.xml +++ b/help_popup/report/help.xml @@ -40,7 +40,7 @@

-
Use Ctrl + P to print this document
+
Use Ctrl + P to print this document