Domain for one2many not working Odoo

11,782

Solution 1

I also faced this problem, and the solution is put domain in .py file, in .xml domain is not working properly.

import_transaction_log_ids = fields.One2many(comodel_name = 'transaction.log','sale_order_id', string = 'Import Transaction Log',domain=[('operation_type','=','import')])

in example operation_type field is in transaction.log model.

Solution 2

Write domain in end_date field, like this:

 <field name="record_ids" >
 <tree string="records_tree">
    <field name="record_id"/>
    <field name="record"/>
    <field name="start_date"/>
    <field name="end_date" domain="[('end_date', '&gt;', cur_date)]"/>
</tree>
</field>

i think it will help you..

Share:
11,782
javatar
Author by

javatar

Updated on June 14, 2022

Comments

  • javatar
    javatar almost 2 years

    In my module I want to filter one2many records based on current date. This is my xml code

    <field name="record_ids" domain="[('end_date', '&gt;', cur_date)]">
        <tree string="records_tree">
            <field name="record_id"/>
            <field name="record"/>
            <field name="start_date"/>
            <field name="end_date"/>
        </tree>
    </field>
    

    cur_date is a functional field I added to get current date.

    My problem is records are not filtered in the view. Also it doesn't show any error message

  • javatar
    javatar almost 9 years
    thanks. can you suggest a method to provide current date as the value?
  • Abdul wahid
    Abdul wahid almost 9 years
    i dont know it works... make a date field in your model and then call that field in your domain filter as 'model rec.date_field_name'..u will get the date in that field
  • DASADIYA CHAITANYA
    DASADIYA CHAITANYA almost 9 years
    @Abdulwahid they want the solution of that Query(Question) not the syntax of domain,how to apply domain in one2many fields.
  • DASADIYA CHAITANYA
    DASADIYA CHAITANYA almost 9 years
    okey no issue but try to understand the proper question and then after you should apply for your answer
  • DASADIYA CHAITANYA
    DASADIYA CHAITANYA almost 9 years
    If your answer may not sure or not correct then just make comment on that question nothing else