forvas
forvas

Reputation: 10189

Why Odoo removes milliseconds in Datetime fields?

I have a method in which self is a simple stock.move record. Besides, as you may know, stock.move model has a Datetime field named date. If I write this code inside the method:

lines = self.search([
    ('date', '=', self.date),
])

It should return me at least the current line. And it does, but only in some servers. Others return nothing. Why? Because if I do a query to get the date in PostgreSQL, the servers which are working OK return 2017-12-27 17:10:00, however, the servers which are working wrong return 2017-12-27 17:10:00.131112. So, for the cases with miliseconds the ORM search method is doing this:

lines = self.search([
    (2017-12-27 17:10:00.131112, '=', 2017-12-27 17:10:00),
])

self.date is returning the Datetime value without the miliseconds and that's why the comparison fails. I need to get the miliseconds too.

How can I manage this?

Upvotes: 3

Views: 800

Answers (1)

Tejas Tank
Tejas Tank

Reputation: 1216

Absolute right, I confirm here odoo Datetime does not keep timestame in UTC, it store datetime in UTC. Even since odoo 5.0 we working on it, till date.

In Odoo 11.0

 id  |        create_date         |         write_date         |    date_expected    
-----+----------------------------+----------------------------+---------------------
  41 | 2017-12-21 13:06:06.927814 | 2017-12-21 13:06:06.927814 | 2017-12-21 13:01:30
   7 | 2017-12-21 08:33:22.431197 | 2017-12-21 08:33:22.431197 | 2017-12-21 08:31:54
  42 | 2017-12-21 13:07:03.659194 | 2017-12-21 13:07:03.659194 | 2017-12-21 13:06:54
   2 | 2017-12-21 07:24:24.953689 | 2017-12-21 07:24:24.953689 | 2017-12-21 07:24:25

Yes. odoo create_date, write_date able to gives you millisecond, might it helpful you. but sure in Datetime, not allow to do so...

In case you need really millisecond based needs, Additional field add to store millisecond, than all it works.

Problem persist in odoo Community and Enterprise edition both.

*** NEED ADDITIONAL SMALL CUSTOMIZATION

Upvotes: 1

Related Questions