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

Openerp 在Odoo服务器操作中重新调整动态域,openerp,odoo-9,odoo-10,Openerp,Odoo 9,Odoo 10,我使用以下代码从Odoo中的服务器操作返回动态域。请注意,我使用的是托管版的Odoo online,所以我是通过Odoo UI来实现这一点的。通过分配action={…}返回操作: 操作={ “域”:{ 'route_id':[('id','in',record.x_all_route_id.id)] } } 当sales.order.line的product\u id字段更改时,会触发此服务器操作。查看销售订单时,如果我更改其中一个销售订单行的产品id,route\u id字段的域将按预期更

我使用以下代码从Odoo中的服务器操作返回动态域。请注意,我使用的是托管版的Odoo online,所以我是通过Odoo UI来实现这一点的。通过分配
action={…}
返回操作:

操作={
“域”:{
'route_id':[('id','in',record.x_all_route_id.id)]
}
}
sales.order.line
product\u id
字段更改时,会触发此服务器操作。查看销售订单时,如果我更改其中一个销售订单行的产品id,
route\u id
字段的域将按预期更新

但是,销售订单行树状图中所有
route\u id
字段的域都会更改。换句话说,如果订单中有3行,并且我更改了其中一行的product\u id,我希望域只更改该行的route\u id字段,而不是销售订单中的每个route\u id字段

我看到的是预期的行为,有没有办法实现我想要的

以下是
x\u all\u route\u id
字段的计算方法:

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)]
对于self中的记录:
routes=record.product\u id.x\u all\u route\u id
如果未记录。产品\u id.x\u是\u预订单\u活动的:
#如果产品没有库存,只保留不需要库存的路线

如果在Odoo中记录.product\U id.x\U sellable\U qty,则可以直接赋值

record.x\u available\u routes=routes.id

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
对于self中的记录:
routes=record.product\u id.x\u all\u route\u id
如果未记录。产品\u id.x\u是\u预订单\u活动的:
#如果产品没有库存,只保留不需要库存的路线

如果在Odoo中记录.product\U id.x\U sellable\U qty,则可以直接赋值

record.x\u available\u routes=routes.id

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
对于self中的记录:
routes=record.product\u id.x\u all\u route\u id
如果未记录。产品\u id.x\u是\u预订单\u活动的:
#如果产品没有库存,只保留不需要库存的路线

如果record.product\u id.x\u selleable\u qty,我认为你不能这样写域。客户端上不存在
.ids
属性。从我看到的情况来看,您必须这样做:
,因为客户端以
write
格式存储字段。例如:
[[6,false,[1,2,3]]
。我最初使用此方法,但在首次添加新SO行并尝试打开route_id下拉列表时会出错。只有保存该行后,它才能正常工作。代码中的
行是什么?视图中的任何位置都没有定义行。此外,我无法获得第一个示例中的语法。当我勾选字段以打开route_id下拉列表,我得到一个错误:
未捕获错误:预期为“]”,获得“(名称)”
我已编辑我的答案行,表示您的销售订单行。你能再试一次吗?第一个例子不起作用。同样的错误。我不认为可以在域中使用类似python的表达式。这是设置字段值的另一种方法,但不会改变结果。如果线路已经存在,则route_id字段将获得相应的域,这意味着它已经保存到SO。但是,如果您在SO中添加新行,并单击route_id字段打开下拉列表,我会得到以下错误:
ValueError:Invalid domain term(u'id',u'in',{u'active':True,u'name':u'Stock',u'sequence':9})
。客户端上不存在
.ids
属性。从我看到的情况来看,您必须这样做:
,因为客户端以
write
格式存储字段。例如:
[[6,false,[1,2,3]]
。我最初使用此方法,但在首次添加新SO行并尝试打开route_id下拉列表时会出错。只有保存该行后,它才能正常工作。代码中的
行是什么?视图中的任何位置都没有定义行。此外,我无法获得第一个示例中的语法。当我勾选字段以打开route_id下拉列表,我得到一个错误:
未捕获错误:预期为“]”,获得“(名称)”
我已编辑我的答案行,表示您的销售订单行。你能再试一次吗?第一个例子不起作用。同样的错误。我不认为可以在域中使用类似python的表达式。这是设置字段值的另一种方法,但不会改变结果。如果线路已经存在,则route_id字段将获得相应的域,这意味着它已经保存到SO。但是,如果在SO中添加新行,并单击route_id字段打开下拉列表,则会出现以下错误:
ValueError:无效的域术语(u'id',u'in',{u'active':True,u'name':u'Stock',u'sequence':9})
<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>