Odoo Help


how to write a function in Odoo 9 date field?

on 4/6/16, 11:20 AM 1,818 views

my date fields is 

salesorder_date = fields.Date('Confirm Sale Date',compute="_currentdate" store=True)
and the method for that is
def _confirmSale(self):
It is not showing the current date not even the date field in the template also.I want to append current date in this date field automatically and
of course can edit the date.

Thanks Jignesh

on 4/7/16, 2:21 PM

Jignesh Mehta

--Jignesh Mehta--
| 6 5 8
Surat, India
--Jignesh Mehta--

Jignesh Mehta
On 4/7/16, 12:11 AM

Hello Paramita,

Try this :-

saleorder_date = fields.Date('Confirm Sale Date', default=fields.datetime.now())

Hope you will put this field in the xml file and no need to write method for current date. Just give default value to field.

Hope it works for you.



Damien Bouvy (dbo)

--Damien Bouvy (dbo)--
| 1 0 1
Grand-Rosière, Belgium
--Damien Bouvy (dbo)--

Damien is a core developer part of Odoo's R&D department. He has developed numerous features on Odoo, including: the subscription application, the billing processes of Odoo Online, refactoring of quotation templates, payment acquirers, etc.

Damien Bouvy (dbo)
On 4/8/16, 10:00 AM

Since this uses the @api.multi decorator, it would be wiser to do something like

def _confirmSale(self):
    for order in self:
        order.salesorder_date = fields.Date.today() # there's a today() helper on the Date field

But since there is no @api.depends on this method, this value will be computed once at the creation of the record then never changed; and it's probably not what you want. BTW, the compute attribute on the field should be the name of the method.

What are you trying to do exactly?

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

2 follower(s)


Asked: 4/6/16, 11:20 AM
Seen: 1818 times
Last updated: 8/16/16, 7:54 AM