Odoo Help


This community 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.


(solution) How to store field readonly in database with onchange method

on 7/8/16, 3:59 AM 374 views

Hey! guys. We found a solution to store readonlyonchange in DB through below code.. CREATE edit, it will store in DB





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)


On 7/8/16, 4:03 AM


I create a field date of birth and age. Age field is specified a readonly true. Im able to store data in database .Im using create and edit method after age value is store in databse. Try to this way

staff_dob = fields.Date(string="Date of Birth")

staff_age = fields.Integer(string="Age",readonly=True,store=True)

def _get_cal(self,a):

if a:

    today = date.today()

    bdate = datetime.strptime(a, '%Y-%m-%d')

    rd = rdelta.relativedelta(today, bdate)

    val= rd.years

return val

Create a onchnage method:


def age_cal_fun(self):

    if self.staff_dob:



    return {}


def write(self, vals):

    if vals.get('staff_dob', False):



    return super(Staff, self).write(vals)


def create(self, vals):

    if vals['staff_dob']:



     return super(Staff, self).create(vals)

Saravanakumar P
On 7/9/16, 6:46 AM


     just add store = True . For yr code


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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 7/8/16, 3:59 AM
Seen: 374 times
Last updated: 7/27/16, 6:40 AM