我使用以下代码从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)]
答案 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>