Domain for one2many does not work Odoo

In my module, I want to filter out one2 entries based on the 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 function field that I added to get the current date.

My problem is that the records are not filtered in the view. Error message also not showing

+4
source share
7 answers

you define the domain in the xml file. therefore this domain does not work.

specify in the .py file.

Example:

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

here cur_date you need to define one function field that shows the current date.

So check this out, maybe this will help you completely :).

+5

, .py, .xml .

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

operation_type transaction.log .

+3

end_date, :

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

, .

+1

' ' '' ''.

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

, . cur_date . , cur_date py.

0

, 2 . . one2many. : sale_order_line sale.order

, , functions_fields [**, store = True ] .

Many2one Many2Many [ ], ,

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

, , many2many ,

0

python: :

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

Use domain = lambdadifferently there is a chance of error when using string values ​​in the domain.

Here xn_stageis in the model mrp.bom.line.

0
source

Source: https://habr.com/ru/post/1599022/


All Articles