Is there any way to forcefully import data into readonly fields in Odoo 9 or 10?
Asked Answered
K

2

6

We have created a custom module in Odoo by inheriting res.partner view and some custom fields, which are readonly, were added. Fields such as customer_since_date and customer_id.

We want to import data to these fields but Odoo does not allow import info into readonly fields.

Is there any way to import data in those fields forcefully?

Korrie answered 21/10, 2016 at 6:43 Comment(7)
How did you make the fields readonly? There are two ways of doing it. 1. directly on field definition (hard way, no import). 2. only readonly in view definition (soft way, import possible).Whitesell
I did it in the hard way. So, you are saying we can just make it read only from view? But is it secure because we don't want to accidentally change the original value.Korrie
If it is read only by view definition a normal user shouldn't be have a possibility to change the value in this view. So you have to check all views of the model.Whitesell
Can you tell me what is a proper way to make a field read only in view definition?Korrie
<field name="phone" position="attributes"> <attribute name="readonly">True</attribute> </field> Is this a proper way? @WhitesellKorrie
Yes that is one proper way to do it.Whitesell
@Whitesell I realize this is quite an old question now, but your answer is still good and relevant. You should post it as a proper answer.Airspeed
C
1

The simple way to make a field read only by view definition is like ,

<field name="phone" readonly="True" />

If you make the field read only by hard way , you can still update the value of such fields by code.

Clio answered 16/5, 2019 at 9:49 Comment(0)
S
0

Simply inherit the model

`_inherit = 'res.partner' `

and create a custom function in which you pass a variable with value you want to assign to the field In my case i was getting data from Point Of Sale module which is mainly javascript i call a rpc query and send a list of values ( contains customer_name & points

    def updating_points(self, data):
       que = self.env['res.partner'].search([('name', '=', data['customer_name'])])
       que.points_earned = data['update_points']

I simply search the res.partner model for specific user update the field i created points_earned

Seiter answered 29/4, 2021 at 11:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.