覆盖api.onchange方法

2024-03-29 10:05:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图重写来自销售订单行类以更改可用性演算。在

但是odoo忽略了重写的方法,仍然使用原始的实现,我的实现只有在重命名方法时才会被调用。在

这是原始方法:

@api.onchange('product_uom_qty', 'product_uom', 'route_id')
    def _onchange_product_id_check_availability(self):
        if not self.product_id or not self.product_uom_qty or not self.product_uom:
            self.product_packaging = False
            return {}
        if self.product_id.type == 'product':
            precision = self.env['decimal.precision'].precision_get('Product Unit of Measure')
            product = self.product_id.with_context(warehouse=self.order_id.warehouse_id.id)
            product_qty = self.product_uom._compute_quantity(self.product_uom_qty, self.product_id.uom_id)
            if float_compare(product.virtual_available, product_qty, precision_digits=precision) == -1:
                is_available = self._check_routing()
                if not is_available:
                    message =  _('You plan to sell %s %s but you only have %s %s available in %s warehouse.') % \
                            (self.product_uom_qty, self.product_uom.name, product.virtual_available, product.uom_id.name, self.order_id.warehouse_id.name)
                    # We check if some products are available in other warehouses.
                    if float_compare(product.virtual_available, self.product_id.virtual_available, precision_digits=precision) == -1:
                        message += _('\nThere are %s %s available accross all warehouses.') % \
                                (self.product_id.virtual_available, product.uom_id.name)

                    warning_mess = {
                        'title': _('Not enough inventory!'),
                        'message' : message
                    }
                    return {'warning': warning_mess}
        return {}

这就是我要实现的:

^{pr2}$

Tags: 方法nameselfidmessageifcheckvirtual
1条回答
网友
1楼 · 发布于 2024-03-29 10:05:32

方法_onchange_product_id_check_availabilitysale_stock模块中定义。在

如果你想替换它的行为,别忘了在你的__manifest__.py数组中添加sale_stock模块。否则将不会调用您的方法,源代码将一如既往地执行。在

'depends': [
    'sale_stock',
    ...
],

相关问题 更多 >