Python odoo上下文字段。弹出窗口的默认值
我与奥多(v9)合作。我有自定义:表单(用于模型1),操作和带有表单的弹出窗口(用于模型2)。 此处示例主要形式:Python odoo上下文字段。弹出窗口的默认值,python,openerp,xml-rpc,odoo-8,odoo-9,Python,Openerp,Xml Rpc,Odoo 8,Odoo 9,我与奥多(v9)合作。我有自定义:表单(用于模型1),操作和带有表单的弹出窗口(用于模型2)。 此处示例主要形式: <record id="my_id_form" model="ir.ui.view"> <field name="name">my_name_form</field> <field name="model">my_model_one</field> <field name="arch" typ
<record id="my_id_form" model="ir.ui.view">
<field name="name">my_name_form</field>
<field name="model">my_model_one</field>
<field name="arch" type="xml">
<form string="Name">
<sheet>
<group>
<field name="partner_id"/>
<!-- button which open popup with my_model_two -->
<button string="Open popup"
name="%(my_module.action_open_popup)d"
type="action"
class="btn-link"/>
</group>
</sheet>
</form>
</field>
</record>
弹出式窗体:
<record id="model_two_form_popup" model="ir.ui.view">
<field name="name">Popup name</field>
<field name="model">my_model_two</field>
<field name="arch" type="xml">
<form string="Popup text">
<sheet>
<group>
<field name="partner_id" invisible="1"/>
<group>
</sheet>
</form>
</field>
</record>
弹出名称
我的第二型
我的问题是:如何将值从主窗体的字段发送到弹出窗体?(partner_id)
我在代码中看到了如何使用活动id、字符串或整数值。但我还没有找到如何发送字段值或如何注册自定义逻辑的方法。
有人能举个小例子吗?提前谢谢。我找到了解决办法。
In-element按钮需要添加如下上下文:
<button string="Open popup"
name="%(my_module.action_open_popup)d"
type="action"
class="btn-link"
<!-- name_of_parameter: name_of_field -->
context="{'partner_id': partner_id}"/>
{'default\u partner\u id':context.get('partner\u id',False),}
新的
您可以做得更好当您使用python方法打开弹出窗口时,上下文可以是动态的,请参见odoo插件中的示例:
@api.multi
def open_popup(self)
#the best thing you can calculate the default values
# however you like then pass them to the context
return {
'name': 'Import Module',
'view_type': 'form',
'view_mode': 'form',
'target': 'new',
'res_model': 'model.name',
'type': 'ir.actions.act_window',
'context': {'default_partner_id':value,'default_other_field':othervalues},
}
在视图xml中:
<field
name="item_ids"
nolabel="1"
domain="['apl_id','=',active_id]"
context="{'res_id':active_id}">
<record id="action_open_popup" model="ir.actions.act_window">
<field name="name">action name</field>
<field name="res_model">my_model_two</field>
<field name="view_id" ref="model_two_form_popup"/>
<!-- set default value to field from context parameter by name -->
<field name="context">{'default_partner_id': context.get('partner_id', False),}</field>
<field name="target">new</field>
</record>
@api.multi
def open_popup(self)
#the best thing you can calculate the default values
# however you like then pass them to the context
return {
'name': 'Import Module',
'view_type': 'form',
'view_mode': 'form',
'target': 'new',
'res_model': 'model.name',
'type': 'ir.actions.act_window',
'context': {'default_partner_id':value,'default_other_field':othervalues},
}
<field
name="item_ids"
nolabel="1"
domain="['apl_id','=',active_id]"
context="{'res_id':active_id}">
_defaults = {
"res_id": lambda self,cr,uid,c:c.get('res_id',False)
}