arsalan.jawed
arsalan.jawed

Reputation: 73

how to set name of a field dynamically in openerp?

Hi I am working on an openerp module . I want to make a field dynamically . I want to take a name of a field from user and then create a field to it . How this can be done ? Can I do it with fields.function to return name, char type ? Plz help

Upvotes: 0

Views: 961

Answers (2)

Adrian Merrall
Adrian Merrall

Reputation: 2499

Do you mean you want a dynamic field on the form/tree view or in the model?

If it is in the view then you override fields_view_get, call super and then process the returned XML for the form type you want adding in the field or manipulating the XML. ElementTree is your friend here.

If you are talking about having a dynamic database field, I don't think you can and OpenERP creates a registry for each database when that database is first accessed and this process performs database refactoring at that time. The registry contains the singleton model instances you get with self.pool.get...

To achieve this you will need to create some kind of generic field like field1 and then in fields_view_get change the string attribute to give it a dynamic label.

Actually, a plan C occurs to me. You could create a properties type of table, use a functional field to read the value for the current user and override fields_view_get to do the form.

Upvotes: 2

Praveen
Praveen

Reputation: 60

You can create Fields Dynamically by the help of class self.pool.get('ir.model.fields') Use Create Function.

Upvotes: 0

Related Questions