From 72d5ab8b9954f77e71e8db6b1d07965e1617bbbf Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Wed, 5 Oct 2011 13:38:46 +0200 Subject: [PATCH] [IMP] email_template: added opt_out flag on res.partner In the context of email templates or for related features like marketing campaigns or automated business document notification, this flag may be used to disable the sending of template-based emails to the partner. It will not prevent sending an email based on a template by default, each feature using a template should implement this if needed. bzr revid: odo@openerp.com-20111005113846-qik6d5gxd4xqeqdj --- addons/email_template/__init__.py | 1 + addons/email_template/__openerp__.py | 4 +++ addons/email_template/res_partner.py | 37 ++++++++++++++++++++++ addons/email_template/res_partner_demo.yml | 9 ++++++ addons/email_template/res_partner_view.xml | 16 ++++++++++ 5 files changed, 67 insertions(+) create mode 100644 addons/email_template/res_partner.py create mode 100644 addons/email_template/res_partner_demo.yml create mode 100644 addons/email_template/res_partner_view.xml diff --git a/addons/email_template/__init__.py b/addons/email_template/__init__.py index 97931ea8bd5..d1cf5b28431 100644 --- a/addons/email_template/__init__.py +++ b/addons/email_template/__init__.py @@ -21,5 +21,6 @@ ############################################################################## import email_template import wizard +import res_partner # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/email_template/__openerp__.py b/addons/email_template/__openerp__.py index e5f83f9ac0c..575550cf2d3 100644 --- a/addons/email_template/__openerp__.py +++ b/addons/email_template/__openerp__.py @@ -61,9 +61,13 @@ Openlabs was kept "data": [ 'wizard/email_template_preview_view.xml', 'email_template_view.xml', + 'res_partner_view.xml', 'wizard/email_compose_message_view.xml', 'security/ir.model.access.csv' ], + "demo": [ + 'res_partner_demo.yml', + ], "installable": True, "active": False, "certificate" : "00817073628967384349", diff --git a/addons/email_template/res_partner.py b/addons/email_template/res_partner.py new file mode 100644 index 00000000000..74d8b4e0693 --- /dev/null +++ b/addons/email_template/res_partner.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Business Applications +# Copyright (c) 2011 OpenERP S.A. +# +# 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 osv import fields,osv + +class res_partner(osv.osv): + """Inherit res.partner to add a generic opt-out field that can be used + to restrict usage of automatic email templates. + This field is unused by default. """ + _inherit = 'res.partner' + + _columns = { + 'opt_out': fields.boolean('Opt-out', help="If checked, this partner will not receive any automated email " \ + "notifications, such as the availability of invoices."), + } + + _defaults = { + 'opt_out': False, + } \ No newline at end of file diff --git a/addons/email_template/res_partner_demo.yml b/addons/email_template/res_partner_demo.yml new file mode 100644 index 00000000000..8eaf48f9e87 --- /dev/null +++ b/addons/email_template/res_partner_demo.yml @@ -0,0 +1,9 @@ +- + Set opt-out to True on all demo partners +- + !python {model: res.partner}: | + partner_ids = self.search(cr, uid, []) + # assume partners with an external ID come from demo data + ext_ids = self._get_external_ids(cr, uid, partner_ids) + ids_to_update = [k for (k,v) in ext_ids.iteritems() if v] + self.write(cr, uid, ids_to_update, {'opt_out': True}) \ No newline at end of file diff --git a/addons/email_template/res_partner_view.xml b/addons/email_template/res_partner_view.xml new file mode 100644 index 00000000000..4790aa7522a --- /dev/null +++ b/addons/email_template/res_partner_view.xml @@ -0,0 +1,16 @@ + + + + + res.partner.opt_out.form + res.partner + form + + + + + + + + + \ No newline at end of file