From e3793fd82f74d4c027b559f13a9e4b46953db117 Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Fri, 27 Jul 2012 14:25:39 +0200 Subject: [PATCH] [IMP] in the contact form, the e-mail field is always visible and if the current user isn't anonymous, will prefilled with his e-mail also replace placeholders by labels bzr revid: abo@openerp.com-20120727122539-5009v5nbsez26eel --- addons/portal_crm/wizard/contact.py | 61 +++++++++++++++++------ addons/portal_crm/wizard/contact_view.xml | 18 +++---- 2 files changed, 54 insertions(+), 25 deletions(-) diff --git a/addons/portal_crm/wizard/contact.py b/addons/portal_crm/wizard/contact.py index 3cf2adac98d..505bb62bb16 100644 --- a/addons/portal_crm/wizard/contact.py +++ b/addons/portal_crm/wizard/contact.py @@ -1,4 +1,26 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-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 openerp.osv import osv, fields +from openerp import SUPERUSER_ID class crm_contact_us(osv.TransientModel): """ Create new leads through the "contact us" form """ @@ -9,13 +31,32 @@ class crm_contact_us(osv.TransientModel): 'company_ids' : fields.many2many('res.company', string='Companies', readonly=True), } - """ Little trick to display companies in our wizard view """ def _get_companies(self, cr, uid, context=None): + """ + Fetch companies in order to display them in the wizard view + + @return a list of ids of the companies + """ r = self.pool.get('res.company').search(cr, uid, [], context=context) return r + def _get_current_user_email(self, cr, uid, context=None): + """ + If the user is logged in (i.e. not anonymous), get the user's email to + pre-fill the email_from field. + + @return current user's email if the user isn't "anonymous", None otherwise + """ + user = self.pool.get('res.users').browse(cr, uid, uid, context=context) + + if (user.login != 'anonymous'): + return user.user_email + else: + return None + _defaults = { - 'company_ids' : _get_companies + 'email_from' : _get_current_user_email, + 'company_ids' : _get_companies, } def create(self, cr, uid, values, context=None): @@ -33,21 +74,11 @@ class crm_contact_us(osv.TransientModel): models implied (like mail.thread, among others, that performs a read when its create() method is called (in method message_get_subscribers()), it is quite complicated to set proper rights for this object. - Therefore, user #1 will perform the creation until a better workaround - is figured out. + Therefore, user SUPERUSER_ID will perform the creation until a better + workaround is figured out. """ values['contact_name'] = values['name'] - - """ - The email_from field only makes sense if the form is submitted by an - anonymous user; otherwise it should be the current user's email. - """ - user = self.pool.get('res.users').browse(cr, uid, uid, context=context) - - if (user.login != 'anonymous'): - values['email_from'] = user.user_email - - crm_lead.create(cr, 1, dict(values,user_id=False), context) + crm_lead.create(cr, SUPERUSER_ID, dict(values,user_id=False), context) """ Create an empty record in the portal_crm.crm_contact_us table. diff --git a/addons/portal_crm/wizard/contact_view.xml b/addons/portal_crm/wizard/contact_view.xml index 5414c8d6ccc..96d55722752 100644 --- a/addons/portal_crm/wizard/contact_view.xml +++ b/addons/portal_crm/wizard/contact_view.xml @@ -15,16 +15,14 @@
- - - - - - -