如何将字段值从主视图传递到 OpenERP 中的弹出窗口 window?

How to pass field value from main view to popup window in OpenERP?

我的产品页面有字段 Item Number (default_code),已在附图中圈出。我的问题是如何将这个项目编号传递给当我单击按钮更多和 select "Replace all in BOM" 时显示的弹出窗口 window,也在附图中圈出。我尝试在弹出 window 中添加字段 "default_code",但它只显示空框。 感谢您的帮助!

主视图如下:

这是我的 XML 代码:

<record id="replace_all_in_BOM_form" model="ir.ui.view">
            <field name="name">replace.all.in.BOM.form</field>
            <field name="model">product.template</field>
            <field name="priority" eval="20"/>
            <field name="type">form</field>
            <field name="arch" type="xml">  
                <field name="default_code" string="Item Number" readonly="0" invisible="0" /> 
            </field> 
         </record>

         <record id="action5" model="ir.actions.act_window">
            <field name="name">Replace all in BOM</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">product.template</field>            
            <field name="view_type">form</field>
            <field name="target">new</field>
            <field name="view_id" ref="replace_all_in_BOM_form"/>
        </record>

您需要在该弹出对象中写入 default_get

试试这个,

def default_get(self, cr, uid, fields, context=None):
    product_obj = self.pool.get('product.product')
    record_ids = context and context.get('active_ids', []) or []
    res = super(product_product, self).default_get(cr, uid, fields, context=context)

    for product in product_obj.browse(cr, uid, record_ids, context=context):
        if 'default_code' in fields:
            #in 'default_code' is a field name of that pop-up window
            res.update({'default_code': product.default_code})

    return res