Odoo Help

Welcome!

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

0

Required field when is customer but not when is supplier

By
Victor
on 5/22/15, 7:48 AM 732 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

Jusab Sida (jsi)

--Jusab Sida (jsi)--
Tiny ERP Pvt Ltd
http://www.odoo.com
874
| 2 1 5
Gandhinagar, India
--Jusab Sida (jsi)--


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

0

Bole

--Bole--
2385
| 5 4 6
Zagreb | Karlovac, Croatia
--Bole--

there is only 10 kind of people the ones that understand binary ... and others

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/22/15, 7:48 AM
Seen: 732 times
Last updated: 5/26/15, 4:23 AM