Use SQL CurrentTimestamp to fill numbered_at

This ensure the timestamp stored is coherent with the create and write date of
the records. As the clock of trytond server can be different from the clock of
the database server.

issue6460
issue4285
review285241002
This commit is contained in:
Cédric Krier
2019-06-26 21:55:46 +02:00
parent ac028b9581
commit 2f8a91c2c9
2 changed files with 36 additions and 17 deletions
+3
View File
@@ -1,3 +1,6 @@
* Use SQL CurrentTimestamp to fill numbered_at
* Rename open_date into numbered_at
Version 5.2.0 - 2019-05-06
* Bug fixes (see mercurial logs for details)
* Add history on payment term line delta
+33 -17
View File
@@ -1,37 +1,53 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import datetime
from sql.functions import CurrentTimestamp
from trytond.model import ModelView, Workflow, fields
from trytond.pool import PoolMeta
from trytond.transaction import Transaction
__all__ = ['Invoice']
class Invoice(metaclass=PoolMeta):
__name__ = 'account.invoice'
open_date = fields.Timestamp('Open Date')
numbered_at = fields.Timestamp("Numbered At")
@classmethod
def __register__(cls, module_name):
super().__register__(module_name)
table_h = cls.__table_handler__(module_name)
table = cls.__table__()
cursor = Transaction().connection.cursor()
# Migration from 5.2: rename open_date into numbered_at
if table_h.column_exist('open_date'):
cursor.execute(
*table.update(
[table.numbered_at],
[table.open_date]))
table_h.drop_column('open_date')
@classmethod
def __setup__(cls):
super(Invoice, cls).__setup__()
cls.party.datetime_field = 'open_date'
if 'open_date' not in cls.party.depends:
cls.party.depends.append('open_date')
cls.invoice_address.datetime_field = 'open_date'
if 'open_date' not in cls.invoice_address.depends:
cls.invoice_address.depends.append('open_date')
cls.payment_term.datetime_field = 'open_date'
if 'open_date' not in cls.payment_term.depends:
cls.payment_term.depends.append('open_date')
cls.party.datetime_field = 'numbered_at'
if 'numbered_at' not in cls.party.depends:
cls.party.depends.append('numbered_at')
cls.invoice_address.datetime_field = 'numbered_at'
if 'numbered_at' not in cls.invoice_address.depends:
cls.invoice_address.depends.append('numbered_at')
cls.payment_term.datetime_field = 'numbered_at'
if 'numbered_at' not in cls.payment_term.depends:
cls.payment_term.depends.append('numbered_at')
@classmethod
def set_number(cls, invoices):
set_open_date = [i for i in invoices if not i.number]
numbered = [i for i in invoices if not i.number or not i.numbered_at]
super(Invoice, cls).set_number(invoices)
if set_open_date:
cls.write(set_open_date, {
'open_date': datetime.datetime.now(),
if numbered:
cls.write(numbered, {
'numbered_at': CurrentTimestamp(),
})
@classmethod
@@ -40,7 +56,7 @@ class Invoice(metaclass=PoolMeta):
def draft(cls, invoices):
super(Invoice, cls).draft(invoices)
cls.write(invoices, {
'open_date': None,
'numbered_at': None,
})
@classmethod
@@ -49,5 +65,5 @@ class Invoice(metaclass=PoolMeta):
default = {}
else:
default = default.copy()
default.setdefault('open_date', None)
default.setdefault('numbered_at', None)
return super(Invoice, cls).copy(invoices, default=default)