gpt4 book ai didi

python - openerp 向导正在调用基本 res.partner 表单而不是我的表单

转载 作者:行者123 更新时间:2023-12-01 05:55:47 27 4
gpt4 key购买 nike

您好,我继承了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。我已经从数据库检查了 search_view_id ,该 id 与我的 View 相同。但我不知道什么错误。但令人惊讶的是,当我看到对客户端的响应时,它就像返回 connection_info 表,意味着它正在调用我的 View 。但我不知道为什么它显示来自基地的 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 &amp; 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>

有人可以帮助我吗,我如何调用我的表单而不是基本表单。我已经尝试了所有方法。提前致谢。

最佳答案

操作定义中的 search_view_id 字段用于指定要使用的 search View ,而不是顾名思义的 form View 。如果您想使用特定的表单 View ,则应使用 view_id 字段(用于指定要打开的主视图,通常为 formtree)。顺便说一下,OpenERP 操作定义中的所有 View 选择字段都可以通过指定 views 字段来覆盖:(view_id, view_mode) 对的有序列表,其中 view_id 可以是 False 以使用默认 View 。这是框架自动添加到常规操作上的计算字段,但也可以手动添加到 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' 的代码。

现在有一些与您想要做的事情相关的附带问题,除了解决眼前的问题之外,您可能还想回答这些问题。

  1. 修改 OpenERP 中现有 View 的最简单方法是继承它。乍一看,您似乎只是尝试在合作伙伴表单 View 上打开一个新选项卡“连接信息”。只需创建一个 Hook 到父 View 的 <notebook> 元素并在其中添加额外的 <page> 的继承 View ,这将是微不足道的(而且更简单)。如果您不希望在所有情况下都显示该选项卡,您可以使用特殊的 attrs 属性向页面添加可见性修饰符。
    因此问题是:为什么不在这里使用这种技术?

  2. 当你不想继承现有 View 时(因为新 View 完全不同),第二个最简单的方法是创建一个相同类型的新 View 并赋予它更高的优先级(较低的 priority字段值)。这将在需要此 View 类型的任何地方自动替换默认 View 。唯一不起作用的情况是打开 View 的操作请求特定的 view_id 时。
    看起来你可以在这里做到这一点,所以第二个问题是:为什么不在这里使用其他技术?

关于python - openerp 向导正在调用基本 res.partner 表单而不是我的表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12656611/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com