5
votes

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

7

7 Answers

6
votes

you are define the domain in the XML file . so this domain it's not work .

please define in the .py file .

For Example :

'record_ids':fields.one2many('model_name','model_id','Record',domain=[('end_date', '>=', 'cur_date')])

here the cur_date you need to define one function field which show the current date.

So Please check this may be it's help full to you :).

3
votes

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.

1
votes

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

0
votes

you can pass only those field in domain those are store in Database. So in that case cur_date is not store in Database. Then also you need to pass into domain so you need to store cur_date field from py.

0
votes

first of all, one2many fields are not for selection purpose. We can create the new records or update the existing records in one2many field. so we cannot apply domain to a one2many field. eg: sale_order_line field in sale.order

moreover one2many fields, functional_fields [**if store=True not specified ] wont store in the table.

Many2one or Many2Many are used for selecting the records [ as well as creating new ones ], so here we can apply domain and we can restrict the user to select some type of records

eg: Many2one- product_id field in sale.order.line
many2many - user_ids field in res.users

So, in order to get your task, try many2many and apply domain, then the records will be filtered

0
votes

domain contains 'field name' 'expression' 'value'. instead of value you given a field

 <field name="record_ids" domain="[('field', 'expression', value)]">
0
votes

Add it in python: Eg:

xn_cutting_ids = fields.One2many('mrp.bom.line', 'bom_id', 'Cutting Lines', domain=lambda self:[('xn_stage','=','cut')])

Use domain = lambda else there is a chance of error while using string values in domain.

Here xn_stage is in mrp.bom.line model.