Help

2

How to auto-change default field value in view?

Avatar
Antanas

Hi,

When there is a default value for a field in model, f.e.

class Foo(orm.Model):
    _name = 'foo.bar'
    _columns = {
        'bar': fields.boolean('Bar'),
    }
    _defaults = {
        'bar': False,
    }

I would like ths default value to be changed to True in one of form views of the model. Is it possible to automatically change default 'bar' value in view, by use of some field attribute etc., without user input?

Avatar
Discard
4 Answers
5
Avatar
Andreas Brueckl
Best Answer

You can do this in the context of the Window Action.

Just write {'default_bar': True} in the context.

1 Comment
Avatar
Discard
Avatar
David
-

Guys I can't get your solution to work here at all. I have a boolean field 'is_repair', and I have been trying to use context 'default_is_repair': True, but it isn't working. Can you help me here?

2
Best Answer

if you want to default boolean you can use 1=True, 0 False

in your python file

_defaults {

'default_is_repair': 1

}

Avatar
Discard
0
Avatar
Med Said BARA
Best Answer

Activate "Developper Mode", Open the form you want, under the drop-down menu "Debug View" you will find "Set Default" ....... Choose the value you want.

Avatar
Discard
0
Avatar
David
Best Answer

Guys I can't get your solution to work here at all. I have a boolean field 'is_repair', and I have been trying to use context 'default_is_repair': True, but it isn't working. Can you help me here?

Avatar
Discard