Odoo Help


set current time in date field

on 6/1/16, 3:57 AM 1,679 views

if user write only in comment then write current datetime in field.

_inherit = "res.partner"

_columns = {

'comment_date' : fields.datetime("comment_date")


def write(self, cr, uid, ids,vals, context=None):

    d = datetime.now().date()


    partner_obj = self.pool.get('res.partner')

    res = super(res_partner, self).write(cr, uid, ids,vals, context=context)

    if vals['comment']:

    p_id = partner_obj.browse(cr, uid,ids, context=context)

    partner_obj.write(cr, uid,p_id, {'comment_date': currentdate},context=context)

return res

--Jignesh Mehta--

Jignesh Mehta
On 6/1/16, 5:51 AM

Hello Vijay,

Try this :-

class Partner(models.Model):

     _inherit = 'res.partner'

     comment_date = fields.datetime('Comment Time')



    def write(self, vals):

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

         if vals.get('comment'):

             res.comment_date = fields.datetime.now()

        return res

Hope it works for you.


Why used api.multi? decorator

on 6/1/16, 8:21 AM

Above code in new api. which version are u used ??

Jignesh Mehta
on 6/1/16, 11:54 PM

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: 6/1/16, 3:57 AM
Seen: 1679 times
Last updated: 6/1/16, 7:31 AM