Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
6 ตอบกลับ
19990 มุมมอง

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

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ธ.ค. 23
16824
2
ส.ค. 18
5439
1
ธ.ค. 16
17327
1
มี.ค. 16
10852
0
พ.ค. 23
2707