简体   繁体   English

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

[英]How can I pass more than one field to a search function? In Odoo 9

I want to set a domain for a field in a 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>

I have created a search function, but it only accepts one operand.我创建了一个搜索函数,但它只接受一个操作数。

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)]

Is there any option to pass more than one field in domain operand?是否有任何选项可以在域操作数中传递多个字段?

You can't pass more than one operand, but you can play with the data type you pass.您不能传递多个操作数,但您可以使用传递的数据类型。 For example, instead of passing a field, you can pass a dictionary/list.例如,您可以传递字典/列表而不是传递字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当只有一些变量需要多个变量时,如何将多个值传递给函数-Python 3 - How can I pass multiple values to a function when only some variables need more than one - python 3 如果odoo中有多个具有相同字段值的记录,如何在many2one下拉列表中仅显示1条记录 - How to display only 1 record in a many2one dropdown if there are more than one record with the same field value in odoo 如何在odoo 12的web表单中将多个记录存储到One2many字段 - How to store more than one record to a One2many field in a web form in odoo 12 使用odoo中的相同字段添加多个条目 - adding more than one entries using same field in odoo 如何在熊猫中传递多个参数来映射函数 - How to pass more than one parameter to map function in panda 如何将多个 function 传递给 sympy.plot - How to pass more than one function to the sympy.plot 如何将具有多个参数的 function 传递给 pandas 转换器? - How to pass a function with more than one argument to pandas converters? 我可以在Django上的模型中使用多个Slug字段吗? - Can I use more than one slug field for a model on Django? 如何使用Orientdb和Flask将多个记录传递给graphql? - How can I pass to graphql more than one record using Orientdb and Flask? 使用多个键处理组后如何将字段的rest加入到Array? - How can I join the rest of the field to Array after processing the group using more than one key?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM