Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
3 Odpovědi
8718 Zobrazení

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

Avatar
Zrušit
Autor Nejlepší odpověď

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.

Avatar
Zrušit
Nejlepší odpověď

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....

Avatar
Zrušit
Nejlepší odpověď

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

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
5
čvn 20
7403
1
dub 16
5506
2
bře 15
7002
2
kvě 24
3356
1
kvě 24
3409