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.

1

how to write a function in Odoo 9 date field?

By
Paramita
on 4/6/16, 11:20 AM 1,205 views

my date fields is 

salesorder_date = fields.Date('Confirm Sale Date',compute="_currentdate" store=True)
and the method for that is
@api.multi
def _confirmSale(self):
self.salesorder_date=datetime.today()
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

Paramita
on 4/7/16, 2:21 PM
8

Jignesh Mehta

--Jignesh Mehta--
2087
| 6 4 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.

Thanks,

1
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

@api.multi
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?

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

2 follower(s)

Stats

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