57 lines
2.1 KiB
Python
57 lines
2.1 KiB
Python
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
|
# this repository contains the full copyright notices and license terms.
|
|
from trytond.pool import Pool, PoolMeta
|
|
from trytond.transaction import Transaction
|
|
from sql import Null
|
|
from datetime import datetime
|
|
|
|
|
|
class Trigger(metaclass=PoolMeta):
|
|
__name__ = 'ir.trigger'
|
|
|
|
@classmethod
|
|
def __setup__(cls):
|
|
super().__setup__()
|
|
cls.action.selection.append(
|
|
('account.invoice|trigger', "Account Invoice"),
|
|
)
|
|
|
|
@classmethod
|
|
def __register__(cls, module_name):
|
|
cursor = Transaction().connection.cursor()
|
|
table = cls.__table_handler__(cls, module_name)
|
|
sql_table = cls.__table__()
|
|
|
|
super(Trigger, cls).__register__(module_name)
|
|
|
|
table_h = cls.__table_handler__(module_name)
|
|
|
|
# Migration from 3.4:
|
|
# change minimum_delay into timedelta minimum_time_delay
|
|
if table.column_exist('minimum_delay'):
|
|
cursor.execute(*sql_table.select(
|
|
sql_table.id, sql_table.minimum_delay,
|
|
where=sql_table.minimum_delay != Null))
|
|
for id_, delay in cursor.fetchall():
|
|
delay = datetime.timedelta(hours=delay)
|
|
cursor.execute(*sql_table.update(
|
|
[sql_table.minimum_time_delay],
|
|
[delay],
|
|
where=sql_table.id == id_))
|
|
table.drop_column('minimum_delay')
|
|
|
|
# Migration from 5.4: merge action
|
|
if (table_h.column_exist('action_model')
|
|
and table_h.column_exist('action_function')):
|
|
pool = Pool()
|
|
Model = pool.get('ir.model')
|
|
model = Model.__table__()
|
|
action_model = model.select(
|
|
model.model, where=model.id == sql_table.action_model)
|
|
cursor.execute(*sql_table.update(
|
|
[sql_table.action],
|
|
[Concat(action_model, Concat(
|
|
'|', sql_table.action_function))]))
|
|
table_h.drop_column('action_model')
|
|
table_h.drop_column('action_function')
|