1 回答

TA貢獻1827條經驗 獲得超8個贊
如果您不希望將記錄記錄放入一個 2 多個字段,請設置 .并返回驗證字典。product_id=False
請嘗試使用以下代碼。
@api.onchange('product_id')
def onchange_product(self):
if self.product_id:
res = {}
selected_lines = rec.env['custom.branch.line'].search(
['&',
('product_id', '=', self.product_id.id),
('branch_id', '=', self.branch_from_id.id)]).mapped('qty')
if not selected_lines:
self.product_id = False
res['warning'] = {'title': _('ValidationError'),
'message': _(
'Current branch has ZERO stock on this product, '
'Please select an available Product')}
return res
添加回答
舉報