[英]How to call a wizard in write function Odoo 14
In write function of 'stock.move' model , I want t return a wizard if some conditions, but that not work.在 'stock.move' 模型的 write 函数中,如果某些条件,我不想返回一个向导,但这不起作用。
Here is my code:这是我的代码:
def write(self, vals):
# Handle the write on the initial demand by updating the reserved quantity and logging
# messages according to the state of the stock.move records.
receipt_moves_to_reassign = self.env['stock.move']
if 'product_uom_qty' in vals:
for move in self.filtered(lambda m: m.state not in ('done', 'draft') and m.picking_id):
if float_compare(vals['product_uom_qty'], move.product_uom_qty,
precision_rounding=move.product_uom.rounding):
self.env['stock.move.line']._log_message(move.picking_id, move, 'stock.track_move_template', vals)
if self.env.context.get('do_not_unreserve') is None:
move_to_unreserve = self.filtered(
lambda m: m.state not in ['draft', 'done', 'cancel'] and float_compare(m.reserved_availability,
vals.get('product_uom_qty'),
precision_rounding=m.product_uom.rounding) == 1
)
move_to_unreserve._do_unreserve()
(self - move_to_unreserve).filtered(lambda m: m.state == 'assigned').write(
{'state': 'partially_available'})
# When editing the initial demand, directly run again action assign on receipt moves.
receipt_moves_to_reassign |= move_to_unreserve.filtered(lambda m: m.location_id.usage == 'supplier')
receipt_moves_to_reassign |= (self - move_to_unreserve).filtered(
lambda m: m.location_id.usage == 'supplier' and m.state in ('partially_available', 'assigned'))
if 'date_deadline' in vals:
self._set_date_deadline(vals.get('date_deadline'))
res = super(StockMove, self).write(vals)
if 'move_line_nosuggest_ids' in vals:
done_qty = vals['move_line_nosuggest_ids'][0][2]['qty_done']
for rec in self:
if rec.product_uom_qty < done_qty:
return self.env["ir.actions.actions"]._for_xml_id("my_module.action_test")
if receipt_moves_to_reassign:
receipt_moves_to_reassign._action_assign()
return res
What's wrong please ?请问怎么了? Any help?
有什么帮助吗? Thanks.
谢谢。
You can not open wizard or any action from write.您无法打开向导或写入任何操作。 if you see write function's return type it's a Boolean
如果你看到 write 函数的返回类型,它是一个布尔值
Thumb rule: you can not return action until browser request/call for it拇指规则:在浏览器请求/调用之前,您不能返回操作
The workaround you could try is, raise ValidationError or UserError with a message.您可以尝试的解决方法是,通过消息引发 ValidationError 或 UserError。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.