Odoo Help

1
8 Answers
5
Avatar

Janeesh

--Janeesh--

4345
| 5 3 6
Cochin, India
--Janeesh--

Odoo Developer

Janeesh
9/24/17, 6:35 AM

You have to use lambda function to get the current time. Otherwise it will take the latest server restart time.

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

Techno-Functional Associate with 7+ years of experience in Odoo (formerly known as OpenERP).

deep
10/26/16, 2:05 AM

In V8 or above, if the class definition is as per latest api, i.e (models.Model)

then use the below like syntax, no need to import any date-related files.


date_action = fields.Datetime('Date current action', required=False, readonly=False, select=True
                                , default=lambda self: fields.datetime.now())




3 Comments
supreeth
11/18/16, 1:26 AM

It works

Nebil Aydi
1/12/18, 4:57 AM

Thanks a lot man .. :)

GLOBAL CREATIVE CONCEPTS TECH CO LTD (iWesabe)
2/14/18, 12:06 AM

Good

3
Avatar

Ray Carnes

--Ray Carnes--
20552
| 9 7 9
Greater Los Angeles, United States
--Ray Carnes--

Business Analyst

OpenERP 6.1, 7.0; Odoo 8.0, 9.0, 10.0, 11.0 and 12.0.

Completed Odoo Functional and Technical Training.

Functional Areas:

  • CRM/Sales

  • Inventory

  • Manufacturing

  • Accounting

  • Purchasing

Major Skills:

  • Business Process Reengineering

  • Efficiency Consulting

  • User Needs and GAP Analysis;

  • Functional and Technical Design;

  • Prototyping and Proof of Concepts;

  • Requirements Specifications;

  • Agile Implementation;

  • Data Migration;

  • Configuration & Customization (UI and code);

  • Integration - Odoo and non Odoo Applications and Services;

  • Training and Knowledge Transfer;

  • Go Live Support;

  • Helpdesk;

  • Version Upgrades and Migration.

  • Accounting Expert.

I have over 20 years of experience empowering and enabling users with enterprise information systems that make a real and measurable difference in their ability to proactively manage their businesses and organizations. 

I am a skilled Communicator and I only take the serious things seriously!

Ray Carnes
8/30/16, 10:24 AM

For v8/v9: You have not defined the field correctly, not using a CAPITAL for Datetime:


'date_action': fields.Datetime('Date current action', required=False, readonly=False, select=True),


For v7: You are mixing the API functions.

Try:

from openerp.osv import fields, osv
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT

date.today().strftime(DEFAULT_SERVER_DATE_FORMAT)
2 Comments
Selverine
8/30/16, 10:40 AM

Hi Ray. Thank you for your answer. I tried with Capital for Datetime but I have the error: AttributeError: 'module' object has no attribute 'Datetime'. Do I need to import a specific class? PS: I am using OpenERP 7 ( sorry to forgot to mention it)

Ray Carnes
9/1/16, 10:35 PM

See my updated answer for v7

-2
Neha Patel (nat)
1/19/17, 5:29 AM

For finding current time use below code.


import time

local = time.asctime(time.localtime())

print "Current time is : ",local

-2
Khaled Hamed
9/29/17, 12:54 AM

 

\Stack\ overflow\ link\ \,\ answer\ \#4\ solved\ the\ issue\ \\\

\
Just remove () from fields.Datetime.now()

to be:

fields.Datetime.now


Ask a Question
Writer
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.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now