diff --git a/base_optional_quick_create/AUTHORS.txt b/base_optional_quick_create/AUTHORS.txt new file mode 100644 index 000000000..7106ca0eb --- /dev/null +++ b/base_optional_quick_create/AUTHORS.txt @@ -0,0 +1 @@ +Lorenzo Battistini diff --git a/base_optional_quick_create/__init__.py b/base_optional_quick_create/__init__.py new file mode 100644 index 000000000..44563ef86 --- /dev/null +++ b/base_optional_quick_create/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2013 Agile Business Group sagl () +# +# 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 . +# +############################################################################## +import model diff --git a/base_optional_quick_create/__openerp__.py b/base_optional_quick_create/__openerp__.py new file mode 100644 index 000000000..2b2a3f8ad --- /dev/null +++ b/base_optional_quick_create/__openerp__.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2013 Agile Business Group sagl () +# +# 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 . +# +############################################################################## + +{ + 'name': "Optional quick create", + 'version': '0.1', + 'category': 'Tools', + 'description': """ +This module allows to avoid to 'quick create' new records, through many2one fields, for a specific model. +You can configure which models should allow 'quick create'. When specified, the 'quick create' option will always open the standard create form. + +Got the idea from https://twitter.com/nbessi/status/337869826028605441 +""", + 'author': 'Agile Business Group', + 'website': 'http://www.agilebg.com', + 'license': 'AGPL-3', + "depends": ['base'], + "data": [ + 'model_view.xml', + ], + "demo": [], + 'test': [ + ], + "active": False, + "installable": True +} diff --git a/base_optional_quick_create/model.py b/base_optional_quick_create/model.py new file mode 100644 index 000000000..fc15593a7 --- /dev/null +++ b/base_optional_quick_create/model.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2013 Agile Business Group sagl () +# +# 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 . +# +############################################################################## + +from openerp.osv import orm, fields +from openerp import SUPERUSER_ID +from openerp.tools.translate import _ + +class ir_model(orm.Model): + + _inherit = 'ir.model' + + _columns = { + 'avoid_quick_create': fields.boolean('Avoid quick create'), + } + + def _wrap_name_create(self, old_create, model): + def wrapper(cr, uid, name, context=None): + raise orm.except_orm(_('Error'), _("Can't create quickly. Opening create form")) + return wrapper + + def _register_hook(self, cr, ids=None): + if ids is None: + ids = self.search(cr, SUPERUSER_ID, []) + for model in self.browse(cr, SUPERUSER_ID, ids): + if model.avoid_quick_create: + model_name = model.model + model_obj = self.pool.get(model_name) + if not hasattr(model_obj, 'check_quick_create'): + model_obj.name_create = self._wrap_name_create(model_obj.name_create, model_name) + model_obj.check_quick_create = True + return True + + def create(self, cr, uid, vals, context=None): + res_id = super(ir_model, self).create(cr, uid, vals, context=context) + self._register_hook(cr, [res_id]) + return res_id + + def write(self, cr, uid, ids, vals, context=None): + if isinstance(ids, (int, long)): + ids = [ids] + super(ir_model, self).write(cr, uid, ids, vals, context=context) + self._register_hook(cr, ids) + return True diff --git a/base_optional_quick_create/model_view.xml b/base_optional_quick_create/model_view.xml new file mode 100644 index 000000000..e1d11126b --- /dev/null +++ b/base_optional_quick_create/model_view.xml @@ -0,0 +1,14 @@ + + + + + ir.model + + + + + + + + + diff --git a/dbfilter_from_header/__init__.py b/dbfilter_from_header/__init__.py new file mode 100644 index 000000000..00ccc56d5 --- /dev/null +++ b/dbfilter_from_header/__init__.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Therp BV (). +# +# 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 . +# +############################################################################## +import re +from openerp.addons.web.controllers import main as web_main + +db_list_org = web_main.db_list + +def db_list(req, force=False): + db_filter = req.httprequest.environ.get('HTTP_X_OPENERP_DBFILTER', '.*') + dbs = db_list_org(req, force=force) + return [db for db in dbs if re.match(db_filter, db)] + +web_main.db_list = db_list diff --git a/dbfilter_from_header/__openerp__.py b/dbfilter_from_header/__openerp__.py new file mode 100644 index 000000000..7baf1f9e7 --- /dev/null +++ b/dbfilter_from_header/__openerp__.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Therp BV (). +# +# 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 . +# +############################################################################## +{ + "name" : "dbfilter_from_header", + "version" : "1.0", + "author" : "Therp BV", + "complexity": "normal", + "description": """ + This addon lets you pass a dbfilter as a HTTP header. + + This is interesting for setups where database names can't be mapped to + proxied host names. + + In nginx, use + proxy_set_header X-OpenERP-dbfilter [your filter]; + + The addon has to be loaded as server-wide module. + """, + "category" : "Tools", + "depends" : [ + 'web', + ], + "data" : [ + ], + "js": [ + ], + "css": [ + ], + "auto_install": False, + "installable": True, + "external_dependencies" : { + 'python' : [], + }, +} diff --git a/email_template_template/__init__.py b/email_template_template/__init__.py new file mode 100644 index 000000000..16e8b082f --- /dev/null +++ b/email_template_template/__init__.py @@ -0,0 +1 @@ +import model diff --git a/email_template_template/__openerp__.py b/email_template_template/__openerp__.py new file mode 100644 index 000000000..6f32b3da0 --- /dev/null +++ b/email_template_template/__openerp__.py @@ -0,0 +1,96 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Therp BV (). +# +# 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 . +# +############################################################################## +{ + "name": "Templates for email templates", + "version": "1.0", + "author": "Therp BV", + "category": 'Tools', + 'complexity': "expert", + "description": """If an organisation's email layout is a bit more +complicated, changes can be tedious when having to do that across several email +templates. So this addon allows to define templates for mails that is referenced +by other mail templates. +This way we can put the layout parts into the template template and only content +in the other templates. Changing the layout is then only a matter of changing +the template template. + + +Usage: +Create an email template with the related document model 'Email Templates'. Now +most of the fields gray out and you can only edit body_text and body_html. Be +sure to use ${body_text} and ${body_html} respectively in your template +template. + +Then select this newly created template templates in one of your actual +templates. + +For example, create a template template +----- +Example Corp logo +Example Corp header +${object.body_text} <- this gets evaluated to the body_text of a template using this template template +Example Corp +Example street 42 +Example city +Example Corp footer +----- + +Then in your template you write + +----- +Dear ${object.partner_id.name}, + +Your order has been booked on date ${object.date} for a total amount of ${object.sum}. +----- + +And it will be evaluated to + +----- +Example Corp logo +Example Corp header +Dear Jane Doe, + +Your order has been booked on date 04/17/2013 for a total amount of 42. +Example Corp +Example street 42 +Example city +Example Corp footer +----- + +Given the way evaluation works internally (body_text of the template template is evaluated two times, first with the instance of email.template of your own template, then with the object your template refers to), you can do some trickery if you know that a template template is always used with the same kind of model (that is, models that have the same field name): + +In your template template: + +------ +Dear ${'${object.name}'}, <-- gets evaluated to "${object.name}" in the first step, then to the content of object.name +${object.body_html} +Best, +Example Corp +------""", + 'website': 'http://therp.nl', + 'images': [], + 'depends': ['email_template'], + 'data': [ + 'view/email_template.xml', + ], + "license": 'AGPL-3', +} +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/email_template_template/model/__init__.py b/email_template_template/model/__init__.py new file mode 100644 index 000000000..90f325845 --- /dev/null +++ b/email_template_template/model/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Therp BV (). +# +# 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 . +# +############################################################################## +import email_template diff --git a/email_template_template/model/email_template.py b/email_template_template/model/email_template.py new file mode 100644 index 000000000..2d1b2091c --- /dev/null +++ b/email_template_template/model/email_template.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Therp BV (). +# +# 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 . +# +############################################################################## +from openerp.osv.orm import Model +from openerp.osv import fields +from openerp.addons.email_template.email_template import mako_template_env + + +class email_template(Model): + _inherit = 'email.template' + + def _get_is_template_template(self, cr, uid, ids, fields_name, arg, + context=None): + cr.execute('''select + id, (select count(*) > 0 from email_template e + where email_template_id=email_template.id) + from email_template + where id in %s''', (tuple(ids),)) + return dict(cr.fetchall()) + + _columns = { + 'email_template_id': fields.many2one('email.template', 'Template'), + 'is_template_template': fields.function( + _get_is_template_template, type='boolean', + string='Is a template template'), + } + + def get_email_template(self, cr, uid, template_id=False, record_id=None, + context=None): + this = super(email_template, self).get_email_template( + cr, uid, template_id, record_id, context) + + if this.email_template_id and not this.is_template_template: + for field in ['body_html']: + if this[field] and this.email_template_id[field]: + try: + mako_template_env.autoescape = False + this._data[this.id][field] = self.render_template( + cr, uid, this.email_template_id[field], + this.email_template_id.model, + this.id, this._context) + finally: + mako_template_env.autoescape = True + return this diff --git a/email_template_template/view/email_template.xml b/email_template_template/view/email_template.xml new file mode 100644 index 000000000..e38cd3c76 --- /dev/null +++ b/email_template_template/view/email_template.xml @@ -0,0 +1,71 @@ + + + + + email.template.form + email.template + + form + + + + + + + + + + {'readonly': [('is_template_template','=',True)]} + + + + 0 + + {'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]} + + + + 0 + + {'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]} + + + + + {'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]} + + + + + {'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]} + + + + + {'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]} + + + + + {'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]} + + + + + {'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]} + + + + 0 + + {'readonly': ['|',('is_template_template','=',True),('model_id', '=', %(email_template.model_email_template)s)]} + + + + + + +