1
votes

My page for product has the field Item Number (default_code), circled in the attached picture. My question is how I can pass this item number to the popup window that is shown when I click on button More and select "Replace all in BOM", also circled in the attached picture. I have tried by adding field "default_code" in popup window, but it just displays empty box. Thanks for your help!

Here is the main view:

enter image description here

And here is my XML code:

<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>
1

1 Answers

1
votes

You need to write default_get in that pop-up object.

try with this,

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