Search code examples
odooodoo-8odoo-10odoo-view

Odoo- How to add multiple views using one class


I am using Odoo 10-e. I created a custom class for order

class Order(models.Model):
    _name = 'amgl.order'
    _description = 'Use this class to maintain all transaction in system.'

    name = fields.Char(string='Name',readonly=True)
    order_line = fields.One2many('amgl.order_line', 'order_id', string='Order Lines')
    total_qty = fields.Float(string='Total Expected')
    total_received_qty = fields.Float(string='Total Received Quantity')
    customer_id = fields.Many2one('amgl.customer', string='Customers', required=True)
    is_pending = fields.Boolean()
    date_opened = fields.Datetime('Date Opened', required=True)
    date_received = fields.Datetime('Date Received')

I also created a view for this class which show all records in tree view . Now i want to create another view named 'Pending Orders' in which i want to show all order where is_pending is true. I am new maybe that's why i am unable to find any example in Odoo Code base.


Solution

  • For this you don't need to create a new view just create a new menu and action and filter the records using domain.

     <record id="action2_...." model="ir.actions.act_window" >
             <field name="name"> Action Title </field>
            ....same as the first action...
              <field name="res_model">your.model</fiel>
             <field name="view_type">form</field>
             <field name="view_mode">tree,form</field>
            <field name="domain">[('is_pending', '=', True)] </field>
       </record> 
    
       <menuitem .....  action="action2_.." />
    

    NB: action can have properties like domain ,context, view_id, search_view_id, view_ids ... etc best way to learn is read about them and see the code in odoo.