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
添加回答
举报