Odoo Help

Welcome!

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.

0

set current time in date field

By
vijay
on 6/1/16, 3:57 AM 707 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()

    currentdate=time.strftime('%Y-%m-%d')

    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

0

Jignesh Mehta

--Jignesh Mehta--
2081
| 6 4 8
Surat, India
--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')

 

    @api.multi

    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.

Thanks,

Why used api.multi? decorator

Odoo
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

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)

Stats

Asked: 6/1/16, 3:57 AM
Seen: 707 times
Last updated: 6/1/16, 7:31 AM