Search code examples
xmlodooodoo-11

Odoo I want to add a tree view inside a wizard


I want to add a tree view inside my wizard.I tried like this:

<record id="view_immediate_transfer" model="ir.ui.view">
        <field name="name">xn_quotation_creation_wiz2</field>
        <field name="model">xn_quotation_creation_wiz</field>
        <field name="arch" type="xml">
            <form string="Warning">
                <group>
                 <field name = "xn_customer_id" />
                </group>
                <group>
                <tree editable = "top">
                    <group>
                        <field name="product"/>
                        <field name="qty"/>
                    </group>
                </tree>
                </group>

                <footer>
                    <button name="save_button" string="Save" type="object" class="btn-primary"/>                
                 </footer>
            </form>
        </field>

But the fields given in tree view are showing like a form view.What to do..? (I want to populate this fields from product master.) enter image description here

Python

class QuotationCreation2(models.TransientModel):
    _name = "xn_quotation_creation_wiz"

     xn_customer_id = fields.Many2one('res.partner',string = "Customer")
     product=fields.Many2one('product.product',string='Product')
     qty=fields.Integer(string='Quantity')

Solution

  • Your view definition is missing the related field you want to show as a tree inside the wizard, for example a One2many or Many2many field.

    <field name="product_master">
      <tree editable = "top">
        <group>
          <field name="product"/>
          <field name="qty"/>
        </group>
      </tree>
    </field>
    

    Transient model is basically same as regular model, difference is that transient models is not persistent in the database, hence used for creating wizards. For any tree view within form, you need a relation of One2many or Many2many type.

    class QuotationCreation2(models.TransientModel):
      _name = "xn_quotation_creation_wiz"
    
      xn_customer_id = fields.Many2one('res.partner',string = "Customer")
      product_master = fields.One2many('xn_quotation_creation_wiz.line','wiz_id')
    
    class QuotationCreationLine(models.TransientModel):
      _name = "xn_quotation_creation_wiz.line"
    
      wiz_id = fields.Many2one('xn_quotation_creation_wiz.line')
      product=fields.Many2one('product.product',string='Product')
      qty=fields.Integer(string='Quantity')