跳至內容
選單
此問題已被標幟
6 回覆
19976 瀏覽次數

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 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])]"/>
頭像
捨棄
作者

That's it!

最佳答案

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


頭像
捨棄
作者

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

最佳答案

Hi,

try

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

頭像
捨棄
作者

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

相關帖文 回覆 瀏覽次數 活動
1
12月 23
16822
2
8月 18
5433
1
12月 16
17319
1
3月 16
10847
0
5月 23
2706