Python 如何检查';写';方法是否在单击按钮后调用?奥多

Python 如何检查';写';方法是否在单击按钮后调用?奥多,python,openerp,odoo-8,odoo-9,odoo-10,Python,Openerp,Odoo 8,Odoo 9,Odoo 10,当我用type='object'单击按钮时,总是调用write方法。我自己也多次调用了一些write方法,并将一个值传递给从按钮调用write的上下文: self.with_context(called_from_btn=True).write({ 'product_route_id': product_id.id, 'route_is_confirmed': True }) 在本例中,在write方法中,

当我用type='object'单击按钮时,总是调用write方法。我自己也多次调用了一些write方法,并将一个值传递给从按钮调用write的上下文:

self.with_context(called_from_btn=True).write({
                'product_route_id': product_id.id,
                'route_is_confirmed': True
            })
在本例中,在write方法中,我可以检查它是否是从按钮调用的,然后根据该按钮执行操作

@api.multi
def write(self, values):
    res = super(Table, self).write(values)
    if 'called_from_btn' in self.env.context:
        ## make actions here
问题是有一个写方法总是被调用,我看不到。我想重写write方法调用,并从_btn传递名为_的上下文,或者做类似的事情。有可能实现这样的目标吗

到目前为止,我尝试的是在单击按钮时返回空的write方法,但没有成功:

return self.with_context(called_from_btn=True).write()

感谢您花时间考虑我的问题。

您可以使用以下方法来完成

 <button name="download_report" type="object" icon="STOCK_SAVE"/>

@api.multi 
def download_report(self):
    self.with_context({'called_from_btn':True}).call_your_method()


@api.multi 
def download_report(self):
    self.call_your_method()
    //call custom method from here

@api.multi
def下载报告(自我):
self.with_context({'called_from_btn':True})。call_your_method()
@api.multi
def下载报告(自我):
self.call_your_method()
//从这里调用自定义方法
您可以直接从按钮方法传递上下文,或用按钮方法编写代码

这可能对你有帮助