Odoo Help

1

Required field when is customer but not when is supplier

By
Victor
on 5/22/15, 7:48 AM 1,401 views

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

1
Victor
On 5/26/15, 4:23 AM

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.

1
Jusab Sida (jsi)
On 5/25/15, 2:34 AM

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

0
Bole
On 5/25/15, 8:10 AM

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

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 5/22/15, 7:48 AM
Seen: 1401 times
Last updated: 1/18/17, 4:59 AM