0
votes

What is the best way to get user input in OpenERP? I have a requirement for user to type in a value (product code) on the form, but I don't know what is the best way to capture that value and pass it to a button action function on button click. Button is on the form as well.

If you can provide guide and sample of code how to create simple wizard with one input field and one button it will be appreciated.

2

2 Answers

0
votes

To get input from the user and then perform some action with it, Wizards are usually used.

A wizard uses a models.TransientModel with fields with the information to get from the user, and a form view that is usually opened as dialog. A button on the form footer area will perform the actions based on those inputs.

For example, see the Load a Translation option in the Settings menu.

0
votes

You need to use a Wizard:

Wizards describe interactive sessions with the user (or dialog boxes) through dynamic forms

Use this for your test_wizard.xml file:

<?xml version="1.0"?>
<openerp>
  <data>

    <record model="ir.ui.view" id="wizard_form_view">
      <field name="name">wizard.form</field>
      <field name="model">your_module.wizard</field>
      <field name="arch" type="xml">
        <form string="Lorem Ipsum">
          <group>
            <field name="input_field"/>
          </group>
          <footer>
            <button name="button_accept" type="object"
                    string="Accept" class="oe_highlight"/>
            <button special="cancel" string="Cancel"/>
          </footer>
        </form>
      </field>
    </record>

    <act_window id="action_wizard"
                name="Title of the wizard"
                res_model="your_module.wizard"
                view_mode="form"
                target="new"
                key2="client_action_multi"/>

  </data>
</openerp>

and this for your test_wizard.py file:

class Wizard(models.TransientModel):
_name = 'your_module.wizard'

input_field = fields.Char(string="Your Input Field", required=True)

@api.multi
def button_accept(self):
    for record in self:
        auxiliar = record.input_field
        print 'You have entered this input:' auxiliar
    return {}

For more official information, take a look HERE