简体   繁体   English

如何在Odoo 10中每次调用python函数

[英]How to call python function every time in Odoo 10

I have a button on purchase.order which does something I want to run the function of the button automatically when Purchase order is created form Sale Order which is done via Procurement. 我在purchase.order上有一个按钮,当通过销售完成从销售订单创建采购订单时,我想自动运行该按钮的功能。

I think this is also possible through javascript when the screen loads(do not know much js). 我认为这也可以通过javascript在屏幕加载时实现(不太了解js)。

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

    @api.multi
    def _unlink_imprint_charges(self):
        self.env['purchase.order.line'].search(['&', ('order_id', '=', self.ids), ('is_charge', '=', True)]).unlink()

    @api.multi
    def charge_set_po(self):
        self._unlink_imprint_charges()
        for obj in self.order_line:
            obj.env['purchase.order.line']._add_imprint_location(obj, self)

I want to call the charge_set_po function when urser clicks on the PO or when Procurement is done. 当用户单击采购订单或完成采购时,我想调用charge_set_po函数。



You create a compute field for this purpose. 为此,您创建一个计算字段。

@api.one
def _foo(self):
   print 'Foo'

action_compute = fields.Char(compute='_foo')

This function will work whenever you click a purchase order in tree view. 每当您在树状视图中单击采购订单时,此功能将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM