嗨,我继承了 CRM 模块。我继承了客户模型并将 redirect_partner_form 覆盖为
from osv import fields, osv
from IPython.Debugger import Tracer; debug_here = Tracer()
class worldcable_customer(osv.osv):
_name = "res.partner"
_description = "worldcable customer"
_inherit = "res.partner"
_columns = {
'id': fields.integer('ID', readonly=True),
'connection_info': fields.one2many('worldcable.connection.info', 'partner_id', 'Connection Info'),
}
def redirect_partner_form(self, cr, uid, partner_id, context=None):
debug_here()
search_view = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'worldcable2', 'view_worldcable_customer_form')
value = {
'domain': "[]",
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'res.partner',
'res_id': int(partner_id),
'view_id': False,
'context': context,
'type': 'ir.actions.act_window',
'search_view_id': search_view and search_view[1] or False
}
debug_here()
return value
worldcable_customer()
并在向导中调用它,
from osv import osv, fields
from tools.translate import _
class crm_lead2partner(osv.osv_memory):
""" Converts lead to partner """
_name = 'worldcable.crm.connection2partner'
_description = 'Connection to Partner'
_columns = {
'action': fields.selection([('exist', 'Link to an existing partner'), \
('create', 'Create a new partner')], \
'Action', required=True),
'partner_id': fields.many2one('res.partner', 'Partner'),
}
def view_init(self, cr, uid, fields, context=None):
"""
This function checks for precondition before wizard executes
"""
if context is None:
context = {}
model = context.get('active_model')
model = self.pool.get(model)
rec_ids = context and context.get('active_ids', [])
for this in model.browse(cr, uid, rec_ids, context=context):
if this.partner_id:
raise osv.except_osv(_('Warning !'),
_('A partner is already defined.'))
def _select_partner(self, cr, uid, context=None):
if context is None:
context = {}
lead = self.pool.get('crm.lead')
partner = self.pool.get('res.partner')
lead_ids = list(context and context.get('active_ids', []) or [])
if not len(lead_ids):
return False
this = lead.browse(cr, uid, lead_ids[0], context=context)
# Find partner address matches the email_from of the lead
res = lead.message_partner_by_email(cr, uid, this.email_from, context=context)
partner_id = res.get('partner_id', False)
# Find partner name that matches the name of the lead
if not partner_id and this.partner_name:
partner_ids = partner.search(cr, uid, [('name', '=', this.partner_name)], context=context)
if partner_ids and len(partner_ids):
partner_id = partner_ids[0]
return partner_id
def default_get(self, cr, uid, fields, context=None):
"""
This function gets default values
"""
res = super(crm_lead2partner, self).default_get(cr, uid, fields, context=context)
partner_id = self._select_partner(cr, uid, context=context)
if 'partner_id' in fields:
res.update({'partner_id': partner_id})
if 'action' in fields:
res.update({'action': partner_id and 'exist' or 'create'})
return res
def open_create_partner(self, cr, uid, ids, context=None):
"""
This function Opens form of create partner.
"""
view_obj = self.pool.get('ir.ui.view')
view_id = view_obj.search(cr, uid, [('model', '=', self._name), \
('name', '=', self._name+'.view')])
return {
'view_mode': 'form',
'view_type': 'form',
'view_id': view_id or False,
'res_model': self._name,
'context': context,
'type': 'ir.actions.act_window',
'target': 'new',
}
def _create_partner(self, cr, uid, ids, context=None):
"""
This function Creates partner based on action.
"""
if context is None:
context = {}
lead = self.pool.get('crm.lead')
lead_ids = context and context.get('active_ids') or []
data = self.browse(cr, uid, ids, context=context)[0]
partner_id = data.partner_id and data.partner_id.id or False
return lead.convert_partner(cr, uid, lead_ids, data.action, partner_id, context=context)
def make_partner(self, cr, uid, ids, context=None):
"""
This function Makes partner based on action.
"""
# Only called from Form view, so only meant to convert one Lead.
lead_id = context and context.get('active_id') or False
partner_ids_map = self._create_partner(cr, uid, ids, context=context)
return self.pool.get('res.partner').redirect_partner_form(cr, uid, partner_ids_map.get(lead_id, False), context=context)
crm_lead2partner()
但它从 Base res.partner 调用原始形式。我已经从 db 检查了 search_view_id,我的视图的 id 相同。但我不知道有什么错误。但令人惊讶的是,当我看到对客户端的响应时,它就像正在返回 connection_info 表,这意味着它正在调用我的视图。但我不知道为什么它从基地显示 res.partner 表格。
DEBUG_RPC_ANSWER:rpc.result:{'domain': '[]', 'view_type': 'form', 'res_model': 'res.partner', 'view_id': False, 'views': [(False, 'tree'), (57L, 'form')], 'search_view_id': 710, 'view_mode': 'form,tree', 'res_id': 57, 'context': {'lang': u'en_US', 'tz': False, 'active_model': 'crm.lead', 'section_id': False, 'search_default_current': 1, 'active_ids': [35L], 'active_id': 35L}, 'type': 'ir.actions.act_window'}
我注意到其中有地址错误
ERROR:tools.expr_eval:{'address': address}
Traceback (most recent call last):
File "/home/noaman/projects/openerp/repository-openerp/Sid/client/bin/tools/__init__.py", line 52, in expr_eval
temp = eval(string, context)
File "<string>", line 1, in <module>
NameError: name 'address' is not defined
我的客户 xml 如下
<openerp>
<data>
<record model="ir.ui.view" id="view_worldcable_customer_form">
<field name="name">worldcable.partner.form</field>
<field name="model">res.partner</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Worldcable Customers" col='1'>
<group col="6" colspan="4">
<group colspan="5" col="6">
<field name="name" select="1"/>
<field name="ref" groups="base.group_extended"/>
<field domain="[('domain', '=', 'partner')]" name="title" size="0" groups="base.group_extended"/>
<field name="lang"/>
</group>
<group colspan="1" col="2">
<field name="customer" select="1" readonly="1"/>
<!-- <field name="employee"/>-->
</group>
</group>
<notebook colspan="4">
<page string="Connection Info">
<field colspan="4" mode="form,tree" name="connection_info" nolabel="1" select="1" height="260">
<form string="Connection Info">
<group colspan="4" col="4">
<field name="mac_address"/>
<field name="telephone_no"/>
<field name="tv_provider"/>
<field name="internet_provider"/>
<field name="phone_provider"/>
<field name="circuit_id"/>
<field name="iigo_number"/>
<field name="dsl_no"/>
<field name="exchange"/>
<field name="service_type"/>
</group>
</form>
<tree string="Connection Info">
<field name="mac_address"/>
<field name="circuit_id"/>
<field name="iigo_number"/>
<field name="dsl_no"/>
<field name="exchange"/>
<field name="tv_provider"/>
<field name="phone_provider"/>
<field name="internet_provider"/>
</tree>
</field>
</page>
<page string="General">
<field colspan="4" mode="form,tree" name="address" nolabel="1" select="1" height="260">
<form string="Partner Contacts">
<group colspan="4" col="6">
<field domain="[('domain', '=', 'contact')]" name="title" size="0"/>
<field name="first_name" colspan="2" string="First Name"/>
<field name="middle_name" colspan="1" string="Middle Name"/>
<field name="last_name" colspan="1" string="Last Name"/>
</group>
<newline/>
<group colspan="2" col="4">
<separator string="Postal Address" colspan="4" col="4" />
<field name="type" string="Type" colspan="2"/>
<field name="floor" colspan="2"/>
<field name="zip"/>
<field name="street" colspan="4"/>
<field name="street2" colspan="4"/>
<field name= "apartment" colspan="2"/>
<field name="city"/>
<field name="state_id"/>
<field name="country_id" completion="1"/>
</group>
<group colspan="2" col="2">
<separator string="Communication" colspan="2" col="2" />
<field name="phone"/>
<field name="mobile"/>
<field name ="other_no"/>
<field name="fax"/>
<field name="email" widget="email"/>
</group>
</form>
<tree string="Partner Contacts">
<field name="name"/>
<field name="zip"/>
<field name="city"/>
<field name="country_id"/>
<field name="phone"/>
<field name="email"/>
</tree>
</field>
</page>
<page string="Sales & Purchases">
<separator string="General Information" colspan="4"/>
<field name="user_id"/>
<field name="active" groups="base.group_extended"/>
<field name="website" widget="url"/>
<field name="date"/>
<field name="parent_id" groups="base.group_extended"/>
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
<newline/>
</page>
<page string="History" groups="base.group_extended" invisible="True">
</page>
<page string="Notes">
<field colspan="4" name="comment" nolabel="1"/>
</page>
</notebook>
</form>
</field>
</record>
<record id="act_my_worldcable_customer_form" model="ir.actions.act_window">
<field name="name">Worldcable Customer</field>
<field name="res_model">res.partner</field>
<field name="view_type">form</field>
<field name="view_mode">tree,calendar,form</field>
<field name="context">{'search_default_current':1}</field>
<field name="help">Worldcable Customer Search</field>
<field name="view_id" ref="view_worldcable_customer_form"/>
</record>
<menuitem id="menu_myview_worldcable_customer" parent="base.myview_menu" name="Customers" icon="terp-partner" action="act_my_worldcable_customer_form" groups="base.group_extended,base.group_sale_salesman" sequence="2"/>
</data>
</openerp>
有人可以帮我吗,我怎么称呼我的表格而不是基本表格。我已经尝试了所有方法。提前致谢。