gpt4 book ai didi

python - 如何在写入函数 Odoo 14 中调用向导

转载 作者:行者123 更新时间:2023-12-04 07:25:46 27 4
gpt4 key购买 nike

在 'stock.move' 模型的写入函数中,我想在某些情况下返回一个向导,但这不起作用。

这是我的代码:

 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

请问有什么问题吗?有什么帮助吗?谢谢。

最佳答案

您无法打开向导或写入任何操作。如果您看到 write 函数的返回类型,它是一个 bool 值

经验法则:在浏览器请求/调用之前,您不能返回操作

您可以尝试的解决方法是,通过消息引发 ValidationError 或 UserError。

关于python - 如何在写入函数 Odoo 14 中调用向导,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68225887/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com