Skip to main content
 首页 » 编程设计

python之如何将多个字段传递给搜索功能在 Odoo 9

2025年02月15日10shanyou

我想为 View 中的字段设置域。

<record id="view_pack_operation_details_form_extend" model="ir.ui.view"> 
  <field name="name">stock.pack.operation.details.form.extend</field> 
  <field name="model">stock.pack.operation</field> 
  <field name="inherit_id" ref="stock.view_pack_operation_details_form"/> 
  <field name="arch" type="xml"> 
    <xpath expr="//field[@name='location_dest_id']" position="replace">             
      <field name="show_all_locations_checkbox"/> 
      <field name="location_dest_id" domain="[('is_empty', '=', picking_destination_location_id)]"/> 
    </xpath> 
  </field> 
</record> 

我创建了一个搜索函数,但它只接受一个操作数。

is_empty = fields.Boolean(compute='compute_is_empty', search='search_is_empty') 
 
 
def search_is_empty(self, operator, operand): 
    ids = [] 
 
    # I need here the value of show_all_locations_checkbox 
    show_all_locations = VALUE_OF_CHECKBOX 
    locations = self.env['stock.location'].search([('location_id', '=', operand)]) 
    for location in locations: 
        stock_quant = len(self.env['stock.quant'].search([('location_id', '=', location.id)])) 
        if show_all_locations: 
            ids.append(location.id) 
        else: 
            if stock_quant == 0: 
                ids.append(location.id) 
 
    return [('id', 'in', ids)] 

是否有任何选项可以在域操作数中传递多个字段?

请您参考如下方法:

您不能传递多个操作数,但您可以使用您传递的数据类型。例如,您可以传递字典/列表而不是传递字段。