Default value for a datetime field

Asked by Kyr Pro on 2011-05-31

Hi all,

How can I set the current date & time as default value for a datetime field?

Kyr Pro

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Web Client Edit question
Assignee:
No assignee Edit question
Solved by:
Kyr Pro
Solved:
2011-06-03
Last query:
2011-06-03
Last reply:
2011-06-01
OpenBMS JSC (openbmsjsc) said : #1

From the UI: enter your desired date/time and right click, choose "Set as default"

From the code: put value in the _defaults = {}, e.g.

        _defaults = {
'appointment_date': lambda * a: time.strftime('%Y-%m-%d %H:%M:%S'),
        }

Kyr Pro (kyr) said : #2

Phong,

I am more interested in the code solution. As I don't have much experience in code, where can I apply the _defaults property. I am using the v5 web client and could not find any such property in the View or Object definitions.

Thank you!

Best regards,

Kyr

Graeme Gellatly (gdgellatly) said : #3

In your module, after you have declared columns then just type a dictionary
like this

_defaults = {
    'some_datetime_field_name' : fields.datetime.now
}

or alternatively the other solution found above.

But this is not something you find in the web-client (at least I wouldn't
think so). This is something you program. Open up the source code for any
main module and you will see plenty of examples of _defaults being used.

On Thu, Jun 2, 2011 at 4:45 AM, Kyr Pro <
<email address hidden>> wrote:

> Question #159791 on OpenERP Web Client changed:
> https://answers.launchpad.net/openobject-client-web/+question/159791
>
> Status: Answered => Open
>
> Kyr Pro is still having a problem:
> Phong,
>
> I am more interested in the code solution. As I don't have much
> experience in code, where can I apply the _defaults property. I am using
> the v5 web client and could not find any such property in the View or
> Object definitions.
>
> Thank you!
>
> Best regards,
>
> Kyr
>
> --
> You received this question notification because you are a member of
> OpenERP Committers, which is an answer contact for OpenERP Web Client.
>

Kyr Pro (kyr) said : #4

Thank you!