This question has been flagged

I want partner field to be mandatory if the account selected in lines is of type payable. i have added type field in the move line related to account type 


type_account = fields.Many2one(string='type',related ='account_id.user_type_id')

and i have put a condition on the partner field which is like below.

<field name="partner_id" attrs="{'required':[('type_account','=','Payable')]}"/>
I have tried this with both "payable" and "payable" no error but doesnt work .
Avatar
Discard

Hope this idea will help; https://goo.gl/BCxCpk

Best Answer

Your related field is a M2o field and you cannot use string value in the domain for relational field. You should create a related field of the type field of user_type_id.

Try this:

type_account = fields.Selection([
('other', 'Regular'),
('receivable', 'Receivable'),
('payable', 'Payable'),
('liquidity', 'Liquidity'),
], string='Type', related=account_id.user_type_id.type)

This will give you the type of the account like: receivable, payable, etc related to the selected account

Avatar
Discard
Author

Thanks for replying ! if you make it a Char field it says

"TypeError: Type of related field account.move.line.type_account is inconsistent with account.account.user_type_id

"

This error as you know means that relational field must be of the same type to which you are relating it too

See my updated answer. Lets make the field selection type.

Author

Thank You so much man. It worked and following attrs works with it

attrs="{'required':[('user_type','=','payable')]}"