Odoo Help

1

button call function from another module in xml

By
omkar
on 3/28/14, 3:23 PM 2,229 views

HI Friends.

I want to call a method for a button , the button is for one class and the action in another class.

How can I call that function with out using class inheritance..

0
nikesh
On 5/26/16, 12:29 AM

Hi omkar,

I think you have created a button in form or tree view of a model and trying to call a method in another model. The method for button should be defined in the model itself. To call method in another model, first you have to define a method in the model in form of which the button is created. Then you can call the method of another model from that method using object of the other model.


For example,

Suppose you have created a button in form view of sale order as:

    <button name="method_a" type="object" string="Call Method" />


If you want to call a method 'method_b'  in purchase order,

class PurchaseOrder(models.Model):
    _inherit = 'purchase.order'

    @api.multi
    def method_b(self):
         -------------------------
 


Then you have to define method 'method_a' in sale order as follows:


class SaleOrder(models.Model):
    _inherit = 'sale.order'

@api.multi
    def method_a(self):
         self.env['purchase.order'].method_b()
         ---------------------------


Thanks & Regards


About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 3/28/14, 3:23 PM
Seen: 2229 times
Last updated: 5/26/16, 12:29 AM