Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
22590 Näkymät

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

Avatar
Hylkää
Paras vastaus

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


Avatar
Hylkää

how to do this in odoo 12