Ayuda

1

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?

Avatar
Descartar
3 Respuestas
1
Avatar
Nacho
Best Answer

You can use a dictionary instead of a single field, for example:


      <field name="location_dest_id" domain="[('is_empty', '=', [picking_destination_location_id,show_all_locations_checkbox])]"/>
1 Comentario
Avatar
Descartar
Avatar
Baintex Technologies S.L.
-

That's it!

0
Avatar
Kinner Vachhani
Best Answer

Hi,

try

self.env['stock.location'].search([('location_id', '=', operand), ('field_2', '=', search_val)])

1 Comentario
Avatar
Descartar
Avatar
Baintex Technologies S.L.
-

What is "search_val"? As input field I only have "operand", I need another input field (show_all_locations_checkbox), but the problem is that I don't know how to pass it via xml to the same function

0
Avatar
Palkesh Baraiya
Best Answer

Hello MouTio,


Yes You can Use More than one filed value in domain.

You can use filter_domain="[]" and inside of you can use '|','&' operator.

for Domain

 filter_domain = "['|',('is_empty', '=', picking_destination_location_id),('field_name', '=', '')]"


And For Search.

locations = self.env['stock.location'].search([('location_id', '=', operand),('filed_name', '=', value)])


2 Comentarios
Avatar
Descartar
Avatar
Baintex Technologies S.L.
-

Yes, I know it, but this is not my question.

I want to know how to pass 2 fields to the search_function (search_is_empty) of the computed field (is_empty).

Avatar
Palkesh Baraiya
-

Ok, But You can Only pass One Function at a Time. Because if you are use Multiple Function at one time than 'search' method was confused to display result or may be it will give you an Error.

Or in base Also only single Function at a time.

https://www.odoo.com/documentation/8.0/reference/orm.html