Odoo Help


HOw to store value in field readonly

on 7/25/16, 4:01 AM 501 views

Hi all

i have code like this

class mtc_hr_analytic_timesheet(osv.osv):

    _inherit = 'hr.analytic.timesheet'

    _columns = {

                    'approver' : fields.many2one('res.users','Approver',readonly=True),


i want value in field approver store to my database. but when i use readonly its doesnt work. the value dissapear when i save.

i have use strore=True but its doesnt work.

anyone can help me how to solve this problem??

Thanks before

Can you give an example code of the contents of xyz_id ?

on 7/25/16, 5:21 AM

for example, to get the id of the ERP Manager

users_ids = self.pool.get('res.users').search(cr, uid, [])

for _id in users_ids:

if self.pool['res.users'].has_group(cr, _id, 'base.group_erp_manager')

xyz_id = _id

Tarek Mohamed Ibrahim
on 7/25/16, 5:49 AM
On 7/26/16, 5:54 AM

Hey Susi!, Hope this will work for u.. 





def adding_samp(self):



def create(self,vals):

    if self.samp_cal3:


    res = super(tokenreservation, self).create(vals)

    return res


def write(self,vals):

    if not self.samp_cal3:

        vals['samp_cal3'] = self.samp_cal1+self.samp_cal2

    res = super(tokenreservation, self).write(vals)

    return res

Odoo Developer
On 7/25/16, 7:06 AM

assighn values like this

cr.execute("UPDATE  hr_analytic_timesheet SET approver = %s where id = %s ", (  your value, id of object ))

On 7/25/16, 6:03 AM

try to write the value into the field using SQL query

On 7/25/16, 4:44 AM

You can update a many2one field, with either an ID or record.

You can’t put any ID or record, a check is made on the relationship to ensure data integrity


Tarek Mohamed Ibrahim

--Tarek Mohamed Ibrahim--
Tarek Mohamed Ibrahim
| 5 3 7
Gîza, Egypt
--Tarek Mohamed Ibrahim--

I am an old VFP developer on ERP

I have moved to 2p since Nov-2014 and started developing with Python on Odoo.



Tarek Mohamed Ibrahim
On 7/25/16, 4:38 AM

 You have to set the value of this field in the create method explicitly

def create(self, cr, uid, val, context=None):
val['approve'] = xyz_id # this is the user id you decided that he will do the approval
res = super(you_class, self).create(cr, uid, val, context)
return res

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 platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 7/25/16, 4:01 AM
Seen: 501 times
Last updated: 7/26/16, 5:54 AM