Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
11052 Widoki


I am trying to update a context from onchange method. Below is code reference-

@api.onchange('country')
def country(self):
    """verify country."""

    self = self.with_context(flag = True)

@api.onchange('state')
def state(self):
    """verify state."""

    print self.env.context

When def country is called i am able to print flag=True in context But when def state method is called i m unable to get flag=True

Also below if my xml code to hide field using context

field name="productname" invisible="context.get('flag', True)"

But flag=True unable to locate under context!!

How i can fix it?


Awatar
Odrzuć
Najlepsza odpowiedź

Hi Shashank,

Context will not work in your case. 

You would need to create a new boolean field and set it's value from the onchange and use that boolean field to show / hide your other field.

Awatar
Odrzuć

Hi Sudhir,

I tried your approach, but the boolean field is not updated in onchange method. Do I need a special flag for the boolean field like store=true or something?

By default normal fields are store=True. Please share your code you are working on.

Thank You , Sudhir sir.

Your answer very help full me +1

Autor Najlepsza odpowiedź

@ Sudhir : Thanx for your feedback.

I have more than 25 fields on form view and i have lots of rules/use cases based on which i have to hide multiple fields.

Example: If condition A is True show field1,2,3,7 and rest of fields hide

If condition B  is True show field1,,7 and rest of fields hide


Would be very difficult for me to add 25 boolean fields to show/hide based on different scenarios

Awatar
Odrzuć

I agree with you but you would need to use field(s) to do that. You can use the context but it will give you the value of the context set in action.

Powiązane posty Odpowiedzi Widoki Czynność
2
sty 25
6804
1
sty 25
1458
computed fields Rozwiązane
1
kwi 24
2792
1
gru 23
5017
2
lis 22
4147