Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4510 Lượt xem

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!

Ảnh đại diện
Huỷ bỏ

need more data

Câu trả lời hay nhất

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. 

Ảnh đại diện
Huỷ bỏ