在Odoo服务器操作中重新调用动态域

时间:2017-04-06 02:15:12

标签: openerp odoo-9 odoo-10

我使用以下代码从Odoo中的服务器操作返回动态域。请注意我在线使用Odoo的托管版本,所以我通过Odoo UI进行此操作。通过分配action = {...}

返回操作
action = {
    'domain': {
        'route_id': [('id', 'in', record.x_all_route_ids.ids)]
    }
}

product_id的{​​{1}}字段更改时,会触发此服务器操作。查看销售订单时,如果我更改其中一个销售订单行的product_id,sales.order.line字段的域将按预期更新。

但是,销售订单行树视图中的所有route_id字段的域都已更改。换句话说,如果订单中有3行,并且我更改了其中一行的product_id,我希望域只更改该行的route_id字段,而不是销售订单中的每个route_id字段。

我看到的是预期的行为,是否有任何方法可以实现我想要的呢?

以下是route_id字段的计算方法:

x_all_route_ids

以下是扩展视图的代码:

for record in self:
    routes = record.product_id.x_all_route_ids

    if not record.product_id.x_is_preorder_active:
       # If the product has no stock, only keep routes that do not require stock
        if record.product_id.x_sellable_qty <= 0:
            routes = routes.filtered(lambda r: r.x_needs_available_inventory == False)

        # If a vendor is unavailable, remove it's route from the list
        for info in record.product_id.seller_ids:
            if not info.x_is_active:
                route = self.env['stock.location.route'].search([('x_is_vendor_dropship_route','=', True), ('x_vendor_id', '=', info.name.id)])
                routes = routes - route

    record['x_available_routes'] = [(6, False, routes.ids)]

1 个答案:

答案 0 :(得分:0)

在Odoo中,您可以直接指定值。

<强> record.x_available_routes = routes.ids

for record in self:
    routes = record.product_id.x_all_route_ids
    if not record.product_id.x_is_preorder_active:
       # If the product has no stock, only keep routes that do not require stock
        if record.product_id.x_sellable_qty <= 0:
            routes = routes.filtered(lambda r: r.x_needs_available_inventory == False)

        # If a vendor is unavailable, remove it's route from the list
        for info in record.product_id.seller_ids:
            if not info.x_is_active:
                route = self.env['stock.location.route'].search([('x_is_vendor_dropship_route','=', True), ('x_vendor_id', '=', info.name.id)])
                routes = routes - route

    record.x_available_routes=routes.ids

在xml中,您应该使用以下代码。

<xpath expr="//field[@name='order_line']/tree/field[@name='route_id']" position="attributes">
    <attribute name="domain">[('route_id', 'in', x_available_routes[0][2])]</attribute>
</xpath>