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
5234 Widoki

Namaste, I have tax field which I want to be required for a particular company, I have tried this code in company onchange:

        if company_id == self.env.ref('x.company').id:
            cr, uid, context = self.env.args
            context = dict(context)
            context.update({'filter_comp': True})
            self.env.args = cr, uid, misc.frozendict(context)

and iN XML

attrs="{'readonly':[('state','not in','draft')],
                                'required':[('company_id','=',context.get('filter_comp',False))]}"/>

it says context is not defined. Am I doing something wrong here?

if not, how can i achieve this?

Awatar
Odrzuć
Najlepsza odpowiedź

You can do this tweak.

make filter_comp as a boolean field

filter_comp = fields.Boolean(default=False)

Then on onchange function :

if company_id == self.env.ref('x.company').id:
      self.filter_comp = True


In XML
attrs="{'readonly':[('state','not in','draft')],
                                'required':[('
filter_comp','=',True)]}"/>

Awatar
Odrzuć
Najlepsza odpowiedź

Context won't be available in the PyObject / Column level, better set it in XML view.


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
lut 16
5964
3
sty 24
14205
2
mar 15
5917
1
lip 19
3739
2
lis 16
6393