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

Hello, I'm trying to make a required field when I'm creating a new customer, but when I'm creating a supplier, this field should be optional. 

I tried this:


<record model="ir.ui.view" id="oms_res_partner_customer_required_form">

<field name="name">oms.res.partner.customer.required.form</field>

<field name="model">res.partner</field>

<field name="inherit_id" ref="base.view_partner_form" />

<field name="arch" type="xml">

<xpath

expr="//field[@name='user_id']"

position = "replace">

<field name="user_id" attrs="{'required': [('customer','=', True)]}"/>

</xpath>

</field>

</record>


This works but when I'm editing a existing customer, but not when I'm creating a new one.

How sould I do it?


Thank you in advance

形象
丢弃
编写者 最佳答案

Hello, I found the solution.


<record model="ir.ui.view" id="oms_res_partner_customer_required_form">

<field name="name">oms.res.partner.customer.required.form</field>

<field name="model">res.partner</field>

<field name="inherit_id" ref="base.view_partner_form" />

<field name="arch" type="xml">

<xpath

expr="//field[@name='user_id']"

position = "replace">

<field name="user_id" attrs="{'required': ['|',('customer','=', 1),('customer','=', True)]}"/>

</xpath>

</field>

</record>

I had to add the condition customer = 1 when I'm creating the partner, and customer = true when I'm editing it.

形象
丢弃
最佳答案

Hi victor,

    I have done same thing by putting attrs in existing field(user_id).


<record id="res_partner_form_inherit" model="ir.ui.view">

<field name="name">res.partner.form.inherit</field>

<field name="model">res.partner</field>

<field name="inherit_id" ref="base.view_partner_form" />

<field name="arch" type="xml">

<field name='user_id' position='attributes'>

<attribute name='attrs'>{'required':[('customer','=',True)]}</attribute>

</field>

.............

</field>

</record>


Hope this will help u little bit....

形象
丢弃
最佳答案

he reason it only works for editing existing customer lays in default values.When you create new record it doess not know if it is customer or supplier.. (both values are false by default)Only when you save the record the system knows the walue of the field....

would try setting default ( add customer=True to context of action opening partners from purchases menu) and define default for vaule customer on res.partner model... that way when you create partner from purchases ( supplier will be marked Ture) and you will have desired behaivour... that is just an ugly workarround but could do the trick....


hope it helps

形象
丢弃
相关帖文 回复 查看 活动
5
6月 20
7403
1
4月 16
5506
2
3月 15
7002
2
5月 24
3356
1
5月 24
3409