Skip to Content
Menu
This question has been flagged
2 Replies
4125 Views

Hi! 


 I need to set parameter to record.field to find string with certaing characters to trigger the record of another field. 


Can anyone help me? 


Thanks!

Avatar
Discard

need more data

Best Answer

If I understand correctly.

What you are trying to do is,
If field_A contains certain string, something happens to field_B.

This can be done by using @api.onchange or @api.depends.
onchange is dynamic even when the record is not saved yet.
depends requires the field to be saved first.

onchange cannot reference fields to another model, so access a field of another model through relational field is NOT doable.
depends does not have such restriction.

For example:

A = fields.Char('Field A')
B = fields.Char('Field B')

@api.onchange('A')
def _check_A(self):
    if 'abc' in str(self.A):
        self.update({'B': 'A contains abc'})


The above code will validate field A contains string 'abc' or not, even when the record is not saved (on creation).
If it does, the moment you click on to field B, 'A contains abc' will show.

Change the behavior accordingly to your needs. 

Avatar
Discard