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

Odoo 14 EE

View: account.move.form

I want to set a conditional domain on the field "res_partner" in account.move.form.

If the "move_type" is "out_invoice" or "out_receipt", the domain would be "[('example0','=',1)]".

If not one of those types, the domain would be "[('example1','=',1)]".

How do I do this?

Avatar
Discard
Best Answer

Hi Russ:

Try this

['|', '&', ('move_type', 'in', ['out_invoice','out_receipt']), ('example0', '=', 1), 
  '&', ('move_type', 'not in', ['out_invoice','out_receipt']), ('example1', '=', 1)]

This should translate into

(move_type is 'out_invoice' or 'out_receipt) AND (example0 = '1') 
OR
(move_type is not 'out_invoice' or 'out_receipt) AND (example1 = '1')

NOTE: You may need to use '&' in place of '&' if you are putting this in XML.

Avatar
Discard
Best Answer

Hello Russ Schneider,

Please refer below method for set conditional domain on res_partner based on move_type in account_move

@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
domain = "[('example1','=',1)]"
res = super(AccountMove, self).fields_view_get(view_id=view_id, view_type=view_type,
toolbar=toolbar, submenu=submenu)
if self._context.get('default_move_type') in ['out_invoice', 'out_receipt'] \
and self._context.get('view_type') == 'form':
if res.get('fields', False):
if 'res_partner' in res.get('fields'):
domain = "[('example0','=',1)]"
res['fields']['res_partner']['domain'] = domain
else:
if 'res_partner' in res.get('fields'):
res['fields']['res_partner']['domain'] = domain
return res

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Discard
Related Posts Replies Views Activity
1
Dec 20
12286
1
Jul 22
1162
1
Jul 22
9481
0
Sep 21
213
1
Jun 21
2567