Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
22631 Представления

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

Аватар
Отменить
Лучший ответ

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


Аватар
Отменить

how to do this in odoo 12