如何使用on_change方法计算总电流值
How do I use the on_change method to calculate total current value
如何在表单中输入特定字段值后实时更改值?例如,从下面的屏幕截图中,如果我输入收到的数量为 10000,则实际库存应计算为 80500。
到目前为止,这是我想出的 on_change 方法的代码:
我想知道这是否是正确的做法
@api.one
@api.onchange('qnty_recieved', 'init_stock')
def _compute_current_stock(self):
qnty_recieved = self.qnty_recieved
init_stock = self.init_stock
current_quantity = self.current_quantity
self.current_quantity = self.qnty_recieved + self.init_stock
下面是我想要实现的截图。
如果我没记错的话,您想根据收到的数量字段实时更改您的实际库存。
使用 depends 方法可以最好地实现这一点。
@api.one
@api.depends('qnty_recieved')
def _compute_current_stock(self):
# Assuming current_quantity as the field name of actual stock
self.current_quantity += self.qnty_recieved
您还应该添加
compute=_compute_current_stock, store=True
您实际股票字段的关键字参数。
如何在表单中输入特定字段值后实时更改值?例如,从下面的屏幕截图中,如果我输入收到的数量为 10000,则实际库存应计算为 80500。
到目前为止,这是我想出的 on_change 方法的代码: 我想知道这是否是正确的做法
@api.one
@api.onchange('qnty_recieved', 'init_stock')
def _compute_current_stock(self):
qnty_recieved = self.qnty_recieved
init_stock = self.init_stock
current_quantity = self.current_quantity
self.current_quantity = self.qnty_recieved + self.init_stock
下面是我想要实现的截图。
如果我没记错的话,您想根据收到的数量字段实时更改您的实际库存。
使用 depends 方法可以最好地实现这一点。
@api.one
@api.depends('qnty_recieved')
def _compute_current_stock(self):
# Assuming current_quantity as the field name of actual stock
self.current_quantity += self.qnty_recieved
您还应该添加
compute=_compute_current_stock, store=True
您实际股票字段的关键字参数。