Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to pass argument to view in openerp?

By
Anna
on 9/9/14, 4:17 PM 4,177 views

Hi, i want to click on a form button i created, call a function for that object and then open new view with the lines of that object modified by the function. I am not quite sure of how to do that, here's my code xml code:

<record id="view_best_rutas_form" model="ir.ui.view">
                <field name="name">best.route</field>
                <field name="model">best.route</field>
                <field name="priority">1</field>
                <field name="type">form</field>
                <field name="arch" type="xml">
                    <form string="Mejores Rutas" version="7.0">
                        <header>
                            <button name="show_best_route" string="Ver Mejor Ruta" class="oe_highlight"/>
                        </header>

                        <field name="id" string="Id"/>
                        <field name="name" string="Nombre"/>
                        
                            <field name="invoices" string="Facturas para Enviar" widget="one2many"  colspan="4" nolabel="1">
                                <tree editable="bottom">
                                        <field name="inv_id" domain="[('has_route','=',False), ('has_destination','=',True)]"/>
                                </tree>
                            </field>
                    
                            <field name="fleets" string="Flotas" widget="one2many"  colspan="4" nolabel="1">
                                <tree editable="bottom">
                                    <field name="fleet_id"/>
                                </tree>
                            </field>
                    </form>
                </field>            
           </record>

Currently i am calling to a function in my model, but i don't know how to open a view derived from that. I want to show the field invoices of that same best.route but with the changes i made in the function.

1
Miku Laitinen
On 9/10/14, 1:20 AM

Add type="object" to your button's attributes and create show_best_route method in your model:

def show_best_route(self, cr, uid, ids, context=None):

Then find the best.route with id defined in the ids variable, make your changes in the invoices as you like and return a view definition:

view_name = 'view_best_route_invoices_or_whatever_your_view_is_called'
view_ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'best_route', view_name)
view_id = view_ref and view_ref[1] or False

return {
    'type': 'ir.actions.act_window',
    'name': _(self._description),
    'res_model': self._name,
    'res_id': ids,
    'view_type': 'form',
    'view_mode': 'form',
    'view_id': view_id,
    'target': 'current',
    'nodestroy': True,
}

This view definition is just an example. You should adjust it to better fit your needs. Also, this method requires that the best.route and the invoices attached to it is saved in the database (=has an id).

Thanks, it works!

Anna
on 9/10/14, 4:59 PM

Thanks, it works!

Anna
on 9/10/14, 4:59 PM
0
Peter Nietz
On 9/9/14, 7:36 PM

From what I understood u have to give that button an action to perform. This requires some JS and Python Code.

U should understand it by using this as a reference:   Trunk Web Module tutorial

0
Alcaline
On 10/18/14, 9:42 AM

Hi got the same problem but in my case i got this in onchange function can please help me in my problem..

How to pass argument to view in openerp?

Hi, i want to click on a form button i created, call a function for that object and then open new view with the lines of that object modified by the function. I am not quite sure of how to do that, here's my code xml code:

<record id="view_best_rutas_form" model="ir.ui.view">
                <field name="name">best.route</field>
                <field name="model">best.route</field>
                <field name="priority">1</field>
                <field name="type">form</field>
                <field name="arch" type="xml">
                    <form string="Mejores Rutas" version="7.0">
                        <header>
                            <button name="show_best_route" string="Ver Mejor Ruta" class="oe_highlight"/>
                        </header>

                        <field name="id" string="Id"/>
                        <field name="name" string="Nombre"/>
                        
                            <field name="invoices" string="Facturas para Enviar" widget="one2many"  colspan="4" nolabel="1">
                                <tree editable="bottom">
                                        <field name="inv_id" domain="[('has_route','=',False), ('has_destination','=',True)]"/>
                                </tree>
                            </field>
                    
                            <field name="fleets" string="Flotas" widget="one2many"  colspan="4" nolabel="1">
                                <tree editable="bottom">
                                    <field name="fleet_id"/>
                                </tree>
                            </field>
                    </form>
                </field>            
           </record>

Currently i am calling to a function in my model, but i don't know how to open a view derived from that. I want to show the field invoices of that same best.route but with the changes i made in the function.

 
 
 
38
| 2 0 1
Asked on 9/10/14, 4:17 AM
 

Add type="object" to your button's attributes and create show_best_route method in your model:

def show_best_route(self, cr, uid, ids, context=None):

Then find the best.route with id defined in the ids variable, make your changes in the invoices as you like and return a view definition:

view_name = 'view_best_route_invoices_or_whatever_your_view_is_called'
view_ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'best_route', view_name)
view_id = view_ref and view_ref[1] or False

return {
    'type': 'ir.actions.act_window',
    'name': _(self._description),
    'res_model': self._name,
    'res_id': ids,
    'view_type': 'form',
    'view_mode': 'form',
    'view_id': view_id,
    'target': 'current',
    'nodestroy': True,
}

This view definition is just an example. You should adjust it to better fit your needs. Also, this method requires that the best.route and the invoices attached to it is saved in the database (=has an id).

 
 
 
92
| 3 1 3
Answered on 9/10/14, 1:20 PM

Thanks, it works!

 
 
 
on 9/11/14, 4:59 AM

Thanks, it works!

 
 
 
on 9/11/14, 4:59 AM
 

From what I understood u have to give that button an action to perform. This requires some JS and Python Code.

U should understand it by using this as a reference:   Trunk Web Module tutorial

 
 
 
110
| 5 1 4
Answered on 9/10/14, 7:36 AM
 

Your answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice.

About This Forum

This community is for professionals and enthusiasts of our products and services.


Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/10/14, 4:17 AM
Seen: 119 times
Last updated: 9/10/14, 1:20 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/9/14, 4:17 PM
Seen: 4177 times
Last updated: 8/23/15, 12:41 PM