odoo V17.4 中报告过滤的自动操作

问题描述 投票:0回答:1

我需要在 odoo V 17.4 中执行自动操作(在线) 以获得生产订单报告的自定义视图,我尝试放置此代码,但它不起作用,现在原始报告失败了

# Obtener todas las órdenes de producción con estado 'confirmed' o 'in_progress'
production_orders = env['mrp.production'].search([
    ('state', 'in', ['confirmed', 'in_progress'])
])

# Crear un diccionario para almacenar solo 2 líneas por tipo de producto
filtered_orders = {}
for order in production_orders:
    product_id = order.product_id.id
    if product_id not in filtered_orders:
        filtered_orders[product_id] = []
    if len(filtered_orders[product_id]) < 2:
        filtered_orders[product_id].append(order)

# Crear una lista con los IDs de las órdenes filtradas
result_ids = [order.id for orders in filtered_orders.values() for order in orders]

# Guardar el resultado para mostrar en la vista
return = {
    'type': 'ir.actions.act_window',
    'name': 'Órdenes Filtradas',
    'res_model': 'mrp.production',
    'view_mode': 'tree',
    'domain': [('id', 'in', result_ids)],
}

当我尝试保存它时,它给出了错误:“SyntaxError:第 19 行语法无效 返回= {“

我需要按状态=“已确认”和“进行中”过滤我的生产订单,条件是按产品类型在报告中只能看到 2 行

python odoo
1个回答
0
投票

在自动化、服务器和 cron python 代码操作中,您必须设置变量

action
作为结果。此操作将被“打开”。

action = {
    'type': 'ir.actions.act_window',
    'name': 'Órdenes Filtradas',
    'res_model': 'mrp.production',
    'view_mode': 'tree',
    'domain': [('id', 'in', result_ids)],
}

无需退货。

© www.soinside.com 2019 - 2024. All rights reserved.