V5 domain and select do not work for certain function fields

Asked by Ferdinand

Example

    def _move_state(self, cr, uid, ids, names=None, arg=False, context=None):
        res = {}
        for line in self.browse(cr, uid, ids, context):
            res[line.id] = False
            for move in line.stock_dispo_production_ids:
                if move.state == 'draft':
                    res[line.id] = True
                    break
        return res

 'move_state' : fields.function(_move_state, method=True, type='boolean', string='Move State' ,help="Returns true if some moves are not done", readonly=True),

this filter does not work
 <field name="domain">[('move_state','=',True)]</field>

also in forms I can not filter for true.

- discovered also other of my apps not allowing to search in similar function fields.

Question information

Language:
English Edit question
Status:
Answered
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) said :
#1

Hello Ferdinand,

Domains can work only on 2 conditions:
1. Field should be having its existence in DB.(i.e. any normal field, store=True for fields.function)
2. If the field is fields.function,Field should have fnct_search member defined which leads to a method that performs search according to the domain supplied.

Example can be found at account/account_move_line.py:
'invoice': fields.function(_invoice, method=True, string='Invoice',
            type='many2one', relation='account.invoice', fnct_search=_invoice_search),

Hope this clears the doubt.
Thanks.

Revision history for this message
Ferdinand (office-chricar) said :
#2

thanks
(1) I knew, but has some disadvantages as it is often not updated without extra coding.
(2) seems to be an overkill if _invoice_search returns the same as _invoice

Can you help with this problem?

Provide an answer of your own, or ask Ferdinand for more information if necessary.

To post a message you must log in.