[FIX] Fixed portal_crm module structure and test. Improved code to invite sale order followers to follow the invoice object.

bzr revid: vta@openerp.com-20121116145407-6hbv0xboq3igvt0l
This commit is contained in:
vta vta@openerp.com 2012-11-16 15:54:07 +01:00
parent 7541e11697
commit 20a50a1866
7 changed files with 38 additions and 65 deletions

View File

@ -2,7 +2,7 @@
############################################################################## ##############################################################################
# #
# OpenERP, Open Source Management Solution # OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # Copyright (C) 2004-2011 OpenERP S.A (<http://www.openerp.com>).
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
@ -19,4 +19,4 @@
# #
############################################################################## ##############################################################################
import wizard import contact

View File

@ -31,7 +31,9 @@ This module adds a contact page (with a contact form creating a lead when submit
""", """,
'author': 'OpenERP SA', 'author': 'OpenERP SA',
'depends': ['crm','portal'], 'depends': ['crm','portal'],
'data': ['wizard/contact_view.xml'], 'data': [
'contact_view.xml',
],
'test': [ 'test': [
'test/contact_form.yml', 'test/contact_form.yml',
], ],

View File

@ -22,14 +22,12 @@
from openerp.osv import osv, fields from openerp.osv import osv, fields
from openerp import SUPERUSER_ID from openerp import SUPERUSER_ID
class crm_contact_us(osv.TransientModel): class contact(osv.TransientModel):
""" Create new leads through the "contact us" form """ """ Create new leads through the "contact us" form """
_name = 'portal_crm.crm_contact_us' _name = 'contact'
_description = 'Contact form for the portal' _description = 'Contact form for the portal'
_inherit = 'crm.lead' _inherit = 'crm.lead'
_columns = { _columns = {
'subject' : fields.char('Subject'),
'body' : fields.text('Content'),
'company_ids' : fields.many2many('res.company', string='Companies', readonly=True), 'company_ids' : fields.many2many('res.company', string='Companies', readonly=True),
} }
@ -85,7 +83,7 @@ class crm_contact_us(osv.TransientModel):
Since they are potentially sensitive, we don't want any user to be able Since they are potentially sensitive, we don't want any user to be able
to read datas generated through this module. Therefore we'll write to read datas generated through this module. Therefore we'll write
these information directly in the crm.lead table and leave blank these information directly in the crm.lead table and leave blank
entries in the portal_crm.crm_contact_us table. entries in the contact table.
This is why the create() method is overwritten. This is why the create() method is overwritten.
""" """
crm_lead = self.pool.get('crm.lead') crm_lead = self.pool.get('crm.lead')
@ -98,17 +96,15 @@ class crm_contact_us(osv.TransientModel):
Therefore, user SUPERUSER_ID will perform the creation. Therefore, user SUPERUSER_ID will perform the creation.
""" """
print values print values
values['name'] = values['subject']
values['contact_name'] = values['partner_name'] values['contact_name'] = values['partner_name']
values['description'] = values['body']
crm_lead.create(cr, SUPERUSER_ID, 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. Create an empty record in the contact table.
Since the 'name' field is mandatory, give an empty string to avoid an integrity error. Since the 'name' field is mandatory, give an empty string to avoid an integrity error.
""" """
empty_values = dict((k, False) if k != 'name' else (k, '') for k, v in values.iteritems()) empty_values = dict((k, False) if k != 'name' else (k, '') for k, v in values.iteritems())
return super(crm_contact_us, self).create(cr, uid, empty_values) return super(contact, self).create(cr, uid, empty_values)
def submit(self, cr, uid, ids, context=None): def submit(self, cr, uid, ids, context=None):
""" When the form is submitted, redirect the user to a "Thanks" message """ """ When the form is submitted, redirect the user to a "Thanks" message """

View File

@ -3,10 +3,10 @@
<data> <data>
<record id="contact_form_view" model="ir.ui.view"> <record id="contact_form_view" model="ir.ui.view">
<field name="name">Wizard form view</field> <field name="name">Contact form</field>
<field name="model">portal_crm.crm_contact_us</field> <field name="model">contact</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Contact wizard view" version="7.0"> <form string="Contact form" version="7.0">
<sheet> <sheet>
<h1>Contact us</h1> <h1>Contact us</h1>
<group class="oe_portal_crm_contact"> <group class="oe_portal_crm_contact">
@ -15,8 +15,9 @@
<field name="partner_name" invisible="1"/> <field name="partner_name" invisible="1"/>
<field name="email_from" invisible="1"/> <field name="email_from" invisible="1"/>
<field name="phone" nolabel="1" placeholder="Your phone number..."/> <field name="phone" nolabel="1" placeholder="Your phone number..."/>
<field name="subject" nolabel="1" placeholder="Subject..." colspan="6" required="1"/> <field name="name" nolabel="1" placeholder="Subject..." colspan="6"/>
<field name="body" nolabel="1" placeholder="Content..." colspan="6" required="1"/> <field name="description" nolabel="1" placeholder="Content..." colspan="6"/>
<!-- <field name="description" nolabel="1" placeholder="Content..." colspan="6" attrs="{'required': [(context.get('user_id'), 'in', 'portal.group_portal.users')]}"/> -->
<button string="Submit" name="submit" type="object"/> <button string="Submit" name="submit" type="object"/>
</group> </group>
<group class="oe_portal_crm_office"> <group class="oe_portal_crm_office">
@ -56,9 +57,6 @@
</group> </group>
</group> </group>
</group> </group>
<!-- <group>
<div class="oe_portal_crm_team"></div>
</group> -->
</sheet> </sheet>
</form> </form>
</field> </field>
@ -67,7 +65,7 @@
<!-- wizard thanks message (shows after submitting the form) --> <!-- wizard thanks message (shows after submitting the form) -->
<record id="wizard_contact_form_view_thanks" model="ir.ui.view"> <record id="wizard_contact_form_view_thanks" model="ir.ui.view">
<field name="name">Wizard thanks message</field> <field name="name">Wizard thanks message</field>
<field name="model">portal_crm.crm_contact_us</field> <field name="model">contact</field>
<!-- give it a low priority to ensure this won't be the default view --> <!-- give it a low priority to ensure this won't be the default view -->
<field name="priority">99</field> <field name="priority">99</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
@ -85,7 +83,7 @@
<record id="action_contact_us" model="ir.actions.act_window"> <record id="action_contact_us" model="ir.actions.act_window">
<field name="name">Contact Us</field> <field name="name">Contact Us</field>
<field name="res_model">portal_crm.crm_contact_us</field> <field name="res_model">contact</field>
<field name="view_mode">form</field> <field name="view_mode">form</field>
<field name="target">inline</field> <field name="target">inline</field>
</record> </record>

View File

@ -6,7 +6,7 @@
- -
As a portal user, I fill in the contact form and submit it. As a portal user, I fill in the contact form and submit it.
- -
!record {model: portal_crm.crm_contact_us, id: contact_us_01}: !record {model: contact, id: contact_us_01}:
name: 'Need information about your contact form module' name: 'Need information about your contact form module'
partner_name: 'Mr. John Doe' partner_name: 'Mr. John Doe'
email_from: 'mister@john.doe' email_from: 'mister@john.doe'
@ -15,7 +15,7 @@
- -
For security reasons, the wizard values is empty. For security reasons, the wizard values is empty.
- -
!python {model: portal_crm.crm_contact_us}: | !python {model: contact}: |
obj = self.browse(cr, uid, ref("contact_us_01")) obj = self.browse(cr, uid, ref("contact_us_01"))
assert not(obj.name or obj.partner_name or obj.email_from or obj.phone or obj.description), 'All the wizard\'s values are not empty' assert not(obj.name or obj.partner_name or obj.email_from or obj.phone or obj.description), 'All the wizard\'s values are not empty'
- -

View File

@ -1,22 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2011 OpenERP S.A (<http://www.openerp.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/>.
#
##############################################################################
import contact

View File

@ -46,25 +46,24 @@ class mail_mail(osv.osv):
group_obj = self.pool.get('res.groups') group_obj = self.pool.get('res.groups')
document = inv_obj.browse(cr, uid, mail.res_id, context=context) document = inv_obj.browse(cr, uid, mail.res_id, context=context)
group_ids = []
# partners = partner_obj.read(cr, uid, partner_ids, ['user_ids'], context=context) for partner in partner_obj.browse(cr, uid, partner_ids, context=context):
# for partner in partners: for user_id in partner.user_ids:
# users = user_obj.read(cr, uid, partner['user_ids'], ['groups_id'], context=context) group_ids += user_id.groups_id
# for user in users: if group_ids:
# for group in group_obj.browse(cr, uid, user['groups_id'], context=context): for group_id in group_ids:
# if group.is_portal == True: if group_id.is_portal == True:
# print 'Hello' inv_obj.message_subscribe(cr, uid, [mail.res_id], partner_ids, context=context)
# inv_obj.message_subscribe(cr, uid, [mail.res_id], partner_ids, context=context) mail_values = {
# mail_values = { 'email_from': 'vta@openerp.com',
# 'email_from': 'vta@openerp.com', 'email_to': 'falcobolger@gmail.com',
# 'email_to': 'falcobolger@gmail.com', 'subject': 'Invitation to follow %s' % document.name_get()[0][1],
# 'subject': 'Invitation to follow %s' % document.name_get()[0][1], 'body_html': 'You have been invited to follow %s' % document.name_get()[0][1],
# 'body_html': 'You have been invited to follow %s' % document.name_get()[0][1], 'auto_delete': True,
# 'auto_delete': True, }
# } mail_id = self.create(cr, uid, mail_values, context=context)
# mail_id = self.create(cr, uid, mail_values, context=context) self.send(cr, uid, [mail_id], recipient_ids=[partner['id']], context=context)
# print mail_values group_ids = []
# self.send(cr, uid, [mail_id], recipient_ids=[partner['id']], context=context)
return super(mail_mail, self)._postprocess_sent_message(cr, uid, mail=mail, context=context) return super(mail_mail, self)._postprocess_sent_message(cr, uid, mail=mail, context=context)