跳至内容
菜单
此问题已终结
2 回复
4278 查看

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?

形象
丢弃
最佳答案

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.

形象
丢弃
最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
1
12月 20
13831
1
7月 22
2485
1
7月 22
10995
0
9月 21
214
1
6月 21
3741