0
votes

am beginner in OpenERP, i want to create a wizard to duplicate an object many time, witch when i click on the button the wizard open a form the content if this form it's ( textbox + ok button) the textBox for to write how many time the wizard will call copy function to copy the object, anyone hav any tuto or something ?

2

2 Answers

0
votes

First create the wizard server side Python

class duplicate_wiz(osv.osv_memory):
  _name = 'duplicate.wiz'
  _description = 'duplicate wizard'
  _columns = {
      'number_of_copies':fields.char('Number of copies', size=2 , required=True),
  }
  _defaults = {                 
      'number_of_copies': '0',
  }

  def duplicate_object(self, cr, uid, ids, context=None):
      data = self.read(cr, uid, ids)[0]
      try:        
          number_of_copies = data['number_of_copies']            
      except:
          raise osv.except_osv(_('Error'), _('Trouble!'))   

      # your duplicate buziness logic
    ...

And render these view as target new to create the wizard.

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

      <record id="dup_view" model="ir.ui.view">
      <field name="name">duplicate.wizard</field>
      <field name="model">duplicate.wiz</field>
      <field name="priority">1</field>
      <field name="arch" type="xml">
         <form string="object duplicater" version="7.0">
            <group col="2">
                <field name="number_of_copies"/>
            </group>
            <footer>
                <button name="duplicate_object" string="_Import" type="object"    class="oe_highlight"/>
                or
                <button string="Cancel" class="oe_link" special="cancel"/>
            </footer>
        </form>
      </field>
    </record>

   <record id="action_duplicate_object" model="ir.actions.act_window">
        <field name="name">duplicater action</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">duplicate.wiz</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
        <field name="target">new</field>
        <field name="view_id" ref="dup_view"/>
    </record>  

    <menuitem id="menu_dup" name="Duplicaters" parent="base.menu_config" sequence="10"/>

    <menuitem id="menu_dup_obj" name="Import File" parent="menu_dup" action="action_duplicate_object"/>    

  </data>
</openerp>

Here is a more complete example of a wizard ( code, xml view render, ... ) Tutorial : OpenErp Module Wizard for CSV import

0
votes

There is a good tutorial: https://doc.openerp.com/v6.1/developer/04_wizard/ Ofc you can look at examples in OpenERP code. Simple example is in openerp technical memento.

You have to create an osv_memory object for wizard's model with method that will do your action. Than create view that will have button calling your action.