您好我继承了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表,意味着它正在调用我的视图。但是我不知道为什么它会从base显示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>
有人可以帮助我,我怎么称呼我的表格而不是基本表格。我已经尝试过所有方法。 提前致谢。
答案 0 :(得分:2)
动作定义中的search_view_id
字段用于指定要使用的 search
视图,而不是 form
视图顾名思义。如果您想使用特定表单视图,则应使用view_id
字段(用于指定要打开的主视图,通常为form
或tree
)。
顺便说一句,OpenERP操作定义中的所有视图选择字段都可以通过指定views
字段来覆盖:对(view_id, view_mode)
对的有序列表,其中view_id
可以是False
使用默认视图。这是框架自动添加常规操作的计算字段,但可以手动添加到Python方法返回的自定义操作中。
以下是如何使用Python方法执行此操作:
# assuming partner_id, context, form_view_id are defined here
return {
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'res.partner',
'res_id': int(partner_id),
'context': context,
'view_id': form_view_id,
# optionally, you could refine by specifying the 'views' explicitly
'views': [(form_view_id, 'form'), # open my form view first,
(False, 'tree')] # then default tree view
}
您会在官方插件的源代码中找到很多类似的示例,搜索返回'views'
或'view_id'
的代码。
现在有一些与您正在尝试做的事情相关的问题,除了解决您的问题之外,您可能还想回答这些问题。
修改OpenERP中现有视图的最简单方法是继承它。初看起来,您似乎只是在合作伙伴表单视图上尝试新的“连接信息”选项卡。简单地创建一个挂接到父视图的<notebook>
元素并在其中添加额外<page>
的继承视图将是微不足道的(并且更简单)。如果您不希望在所有情况下都显示该标签,则可以向页面添加可见性修饰符,并使用特殊的attrs
属性。
因此,问题是:你为什么不在这里使用这种技术?
如果您不想继承现有视图(因为新视图完全不同),第二个最简单的方法是创建相同类型的新视图并赋予其更高的优先级(更低{ {1}}字段值)。这将自动替换需要此视图类型的默认视图。唯一的情况是,当打开视图的操作请求特定的view_id时,它不起作用 看来你可以在这里做,所以第二个问题是:为什么不在这里使用其他技术?