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

Hi everyone. I am sure there is an easy answer to this that I cannot find.


How do you add a custom field to a radio selection.

i.e. in res.partner company_type radio selection - individual and company

    we need to add a new field specific to the individual not the company.

    so it does not need to be seen on company form just individual


thanks in advance  

形象
丢弃

Hi Justin: What are you using to do the customization - Studio or python module ?

编写者

Python inherit

最佳答案

Hi Justin:

You will need to do 2 things:

  1. Add a new field to the model

  2. Display the field in the view and make it visible only when the contact is an individual

In your example, define the field, spouse, in the model. Then add the field to the view and make it visible only for individuals like so by making it invisible if the contact is a company.

<field name="spouse" attrs="{'invisible': [('is_company', '=', True)]}" />

NOTE: I'm assuming you're familiar with using inheritance for models and views to make the necessary changes.

形象
丢弃
编写者

Thank you, I do understand inheritance. Just didn't know if that string belonged in the models or xml. Looking at it the correct xpath would be-

<xpath expr="//field[@name='mobile']/.." position="after">

<label for="spouse"/>

<div>

<field name="spouse" attrs="{'invisible': [('is_company', '=', True)]}" />

</div>

</xpath>

Thanks again

最佳答案

Just do like this : <field name="gender" widget='radio' options="{'horizontal': true}"/>

Python: gender = fields.Selection([('foo', 'foooooooo'), ('bar', 'baaaaaaaar')], default='foo')


形象
丢弃
编写者

hmmm I don't want to add another selection field. Lets say I want to add a spouse = fields.Char to foo. how would you present that in models and xml?

相关帖文 回复 查看 活动
5
9月 20
4984
11
1月 24
13511
2
8月 20
3439
1
6月 16
10144
1
3月 15
11371