Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
8717 Widoki

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

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
5
cze 20
7403
1
kwi 16
5506
2
mar 15
7002
2
maj 24
3356
1
maj 24
3409