1
votes

I have added button "Search" to my custom, new view. Whenever I click "Search" a record is either inserted or updated in mrp_bom table. I could not find the reason why. I expect the button does nothing, for now.

Here is code in py:

class mrp_bom(osv.Model):
    _inherit = 'mrp.bom'

    def action_search(self, cr, uid, ids, vals, context=None):
        ptemplid = self.browse(cr, uid, ids[0], context=context).product_tmpl_id
        print "\n\n Inside action_search() ptemplid ", ptemplid  

and here is xml:

  <record id="bom_where_use_form" model="ir.ui.view">
        <field name="name">bom.where.use.form</field>
        <field name="model">mrp.bom</field>
        <field name="priority" eval="20"/>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <label for="product_tmpl_id" string="Product Name" />
            <field name="product_tmpl_id" on_change="onchange_product_tmpl_id(product_tmpl_id, 0, context)"/> 
            <button name="action_search" string="Search" type="object" class="oe_highlight"/>
        </field>         
    </record> 
1

1 Answers

0
votes

Whenever a button action is executed, it first saves the record. So it the record is new, then create method will be executed otherwise write function is executed for that record. Then only the button action executes.