title: Using popup window to get user inputs and use those inputs in button's function in OpenERP
body: <p>I would like to ask community to evaluate my solution in OpenERP. I am using Odoo v8. </p>
  
  <p>I have created a popup window with two fields, original_code and replacement_code, and the button with caption "Replace". The popup is launched from parent page "More" button dropdown option. </p>
  
  <p>Use case is that user will type in product code in the field original_code (the field looks like edit textbox) while replacement code field is automatically populated and is read only. Pressing the button "Replace" the button action is triggered that replaces the code in the related tables in database.</p>
  
  <p>I have created new model, new class, and hence new table in database, nk_product_template, that inherits from product_template. The reason I created new table is to have my button action inserts records in this table and not in product_template table. I have added two new char fields to the table, original_code and replacement code. This model is referenced in XML code for popup window.</p>
  
  <p>My button action function is defined in the class nk_product_template and its name is action_replace() which has logic to replace product code. Whenever I click on button "Replace" it always first inserts the record in the table nk_product_template (no code is written for insertion, it's automatic as I understand) and returns id of that record which I use to retrieve original_code and replacement_code values from the table inside button's action_replace() and use those values in the code replacement logic.</p>
  
  <p>I am wondering is this the correct way to solve the use case, and if it is not a correct approach, how would you solve it. My major question is do I need to have new class (hence new model and new table) for each popup window to set and get field values? Your comments are greatly appreciated.</p>
  
  <p>Here is the XML code where the popup window is defined:</p>
  
  <pre><code>&lt;record id="replace_all_in_BOM_form" model="ir.ui.view"&gt;
      &lt;field name="name"&gt;replace.all.in.BOM.form&lt;/field&gt;
      &lt;field name="model"&gt;nk.product.template&lt;/field&gt;
      &lt;field name="priority" eval="20"/&gt;
      &lt;field name="type"&gt;form&lt;/field&gt;
      &lt;field name="arch" type="xml"&gt;
          &lt;group&gt;
              &lt;field name="original_code" string="Original Code" style="width: 
              10%%" readonly="0" /&gt;
              &lt;field name="replacement_code" string="Replacement Code" 
              style="width: 10%%" readonly="1" invisible="0" /&gt;
              &lt;field name="default_code" string="Replacement" readonly="1"    
              invisible="1"  /&gt;   
              &lt;field name="uom_id" invisible="1"  /&gt; 
              &lt;field name="uom_po_id" invisible="1"   /&gt;
              &lt;field name="type" invisible="1"   /&gt;   
              &lt;field name="categ_id" invisible="1"   /&gt; 
              &lt;field name="name" invisible="1" /&gt;
          &lt;/group&gt;
          &lt;button type="object" string="Replace" name="action_replace" /&gt;
      &lt;/field&gt; 
  &lt;/record&gt;
  </code></pre>
  
  <p>My py code is as follows:</p>
  
  <pre><code>class nk_product_template(osv.osv):
      _inherit = 'product.template'
      _name = 'nk.product.template'
  
      _columns = {
          'replacement_code' : fields.char('Replacement Code', select=True),
          'original_code' : fields.char('Original Code', select=True),
      }
      def default_get(self, cr, uid, fields, context=None):
          # &lt;code to automatically populate replacement_code field&gt;
          # ...   
  
      def action_replace(self, cr, uid, ids, context=None):
          # &lt;code that replaces product code&gt;
          # ...
  </code></pre>