Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
6 Răspunsuri
19978 Vizualizări

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?

Imagine profil
Abandonează
Cel mai bun răspuns

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])]"/>
Imagine profil
Abandonează
Cel mai bun răspuns

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


Imagine profil
Abandonează
Autor

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

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

Cel mai bun răspuns

Hi,

try

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

Imagine profil
Abandonează
Autor

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

Related Posts Răspunsuri Vizualizări Activitate
1
dec. 23
16822
2
aug. 18
5433
1
dec. 16
17319
1
mar. 16
10847
0
mai 23
2706