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?

ChesuCR
  • 9,352
  • 5
  • 51
  • 114
Vaibhav Bhavsar
  • 493
  • 3
  • 15
  • 3
    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). – CZoellner Oct 21 '16 at 07:15
  • 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. – Vaibhav Bhavsar Oct 24 '16 at 07:00
  • 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. – CZoellner Oct 24 '16 at 07:18
  • Can you tell me what is a proper way to make a field read only in view definition? – Vaibhav Bhavsar Oct 26 '16 at 04:42
  • ` True ` Is this a proper way? @CZoellner – Vaibhav Bhavsar Oct 26 '16 at 04:44
  • 1
    Yes that is one proper way to do it. – CZoellner Oct 26 '16 at 05:58
  • @CZoellner 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. – travisw Feb 01 '19 at 21:04

2 Answers2

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.

Ajmal JK
  • 813
  • 4
  • 14
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