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

How to block Many2One value Changes

By
sridhar
on 4/7/14, 9:12 AM 1,619 views

My concept is small, I have a many2one field, if i select one value means sequence number is created automatically based on Many2One value. Ex. many2one field like this ABC, BCD, if i select ABC and save it, its sequence is ABC001 it is correct, but again i can edit this Many2One like BCD, It is a Wrong record. Once user select ABC means and save it, again he wont change the value. how to do it.

2

Nehal

--Nehal--
2090
| 5 2 8
Ahmadabad, India
--Nehal--
Nehal
On 4/7/14, 9:16 AM

Hi,

You can create one boolean field:test and then set that field as True on record creation. Then apply readonly attrs(boolean=True) for your many2one field. e.g. <field name="m2o_field" attrs="{'readonly': [('test','=',True)]}"/>

0
Serge
On 4/7/14, 11:19 AM

I have a other solution, not tested but in theory work fine.

In your object columns add

'id': fields.integer('ID',  readonly=True),

That will force openerp to add ID field in the object column property

After in your view, add

<field name="id" invisible="1"/>

That will but the ID field invisible on your form, and allow the next change to work

<field name="m2o_field" attrs="{'readonly': [('id','!=',False)]}"/>

That will put the field on readonly when the record will be create. So dont forget to put required=true for the m2o_field, because if you forget to select a value, after creation you cant change it.

I prefer this solution, because no need to create a new field, no need to manage field to set it when record create.

Give me a feedback if you do it, please

0
Kazim Mirza
On 4/7/14, 1:49 PM

You can block the value change of any many2one fields with widget attribute like, widget="many2one_list" example : <field name="id" widget="many2one_list"/> its gives a list formate and you cant change it

like this you can set other fields :one2many_list : many2one_list

read again, he wanna can SET a value at record creation, but disable change after, so edit record CANT change de value. He dont wanna have a list not modifiable, he wanna CANT change the selected.

Serge
on 4/7/14, 3:49 PM

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

0 follower(s)

Stats

Asked: 4/7/14, 9:12 AM
Seen: 1619 times
Last updated: 3/16/15, 8:10 AM