Skip to Content
Menu
This question has been flagged
2 Replies
1117 Views

Hello guys:


I'm wondering if it's possible to re-set a certain field's attribute(s) in the method 'create' ? 


The  scenario is :  

when we draft a new record,  some fields are computed depending on some other fields;

After saving the record, computed fields are stored and would be used in next business unit. So I want the fields fixed so that the next units linked to them will not be disturbed. 

So , I want the computing dependencies change to 'readonly'  once record created. 

Any solutions please?  Thank you .

Avatar
Discard
Best Answer

Hi,

To make computed fields read-only after a record is saved in Odoo, define the field with store=True and make it computed only when the record is new. In the XML view, use the readonly attribute to set the field as read-only once the record has been created. Additionally, override the write method to prevent further changes to the computed field after the record is saved.


For example set the attribute as following to set the field readonly if the record is created:

<field name="computed_field" readonly="id"/>


Hope it helps.

Avatar
Discard
Author Best Answer

Hi Cybrosys:

Thanks for your reply.  Once record saved, what i want to be unchangable is the dependency,  such as the field 'country_code' in the following example.  Anyway,  i think the basic mechanism to dynamically set a field 'readonly' is same as your solution.

I am thinking to apply some other fields in the 'readonly ' expression, like 'state'.  

Once the record turns to official , the dependency field is readonly ;  Once the record roll back to 'draft' , the dependency field can be modified as usual.

Avatar
Discard
Related Posts Replies Views Activity
0
Feb 25
495
0
Jan 25
428
1
Dec 24
658
1
Jun 22
4461
1
Feb 19
4311