Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
6 Risposte
19969 Visualizzazioni

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
Abbandona
Risposta migliore

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])]"/>
Avatar
Abbandona
Autore

That's it!

Risposta migliore

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


Avatar
Abbandona
Autore

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

Risposta migliore

Hi,

try

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

Avatar
Abbandona
Autore

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

Post correlati Risposte Visualizzazioni Attività
1
dic 23
16821
2
ago 18
5432
1
dic 16
17316
1
mar 16
10844
0
mag 23
2704