2014-12-02 12:55:19 +01:00
|
|
|
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
|
|
|
|
# this repository contains the full copyright notices and license terms.
|
2014-11-24 14:01:22 +01:00
|
|
|
from sql import Null
|
2015-07-13 23:58:23 +02:00
|
|
|
from sql.conditionals import Case
|
2014-11-24 14:01:22 +01:00
|
|
|
|
2009-12-23 00:04:42 +01:00
|
|
|
from trytond.model import ModelView, ModelSQL, fields
|
2012-05-14 15:36:34 +02:00
|
|
|
from trytond.transaction import Transaction
|
2013-09-06 22:34:16 +02:00
|
|
|
from trytond import backend
|
2013-02-04 19:56:02 +01:00
|
|
|
from trytond.pyson import Eval
|
2009-12-23 00:04:42 +01:00
|
|
|
|
2012-09-24 22:17:54 +02:00
|
|
|
__all__ = ['DashboardAction']
|
|
|
|
|
|
2009-12-23 00:04:42 +01:00
|
|
|
|
|
|
|
|
class DashboardAction(ModelSQL, ModelView):
|
|
|
|
|
"Dashboard Action"
|
2012-09-24 22:17:54 +02:00
|
|
|
__name__ = "dashboard.action"
|
2009-12-23 00:04:42 +01:00
|
|
|
user = fields.Many2One('res.user', 'User', required=True,
|
2012-03-05 10:53:02 +01:00
|
|
|
select=True)
|
2013-09-06 22:34:16 +02:00
|
|
|
sequence = fields.Integer('Sequence')
|
2009-12-23 00:04:42 +01:00
|
|
|
act_window = fields.Many2One('ir.action.act_window', 'Action',
|
2011-04-09 13:52:38 +02:00
|
|
|
required=True, ondelete='CASCADE', domain=[
|
2012-03-27 10:43:36 +02:00
|
|
|
('res_model', '!=', None),
|
2011-04-09 13:52:38 +02:00
|
|
|
('res_model', '!=', ''),
|
2012-12-23 17:44:43 +01:00
|
|
|
('usage', '=', 'dashboard'),
|
2013-02-04 19:56:02 +01:00
|
|
|
# XXX copy ir.action rule to prevent access rule error
|
|
|
|
|
['OR',
|
|
|
|
|
('groups', 'in', Eval('context', {}).get('groups', [])),
|
|
|
|
|
('groups', '=', None),
|
|
|
|
|
],
|
2011-04-09 13:52:38 +02:00
|
|
|
])
|
2009-12-23 00:04:42 +01:00
|
|
|
|
2012-09-24 22:17:54 +02:00
|
|
|
@classmethod
|
|
|
|
|
def __setup__(cls):
|
|
|
|
|
super(DashboardAction, cls).__setup__()
|
|
|
|
|
cls._order.insert(0, ('sequence', 'ASC'))
|
2009-12-23 00:04:42 +01:00
|
|
|
|
2012-09-24 22:17:54 +02:00
|
|
|
@classmethod
|
|
|
|
|
def __register__(cls, module_name):
|
2013-09-06 22:34:16 +02:00
|
|
|
TableHandler = backend.get('TableHandler')
|
2012-05-14 15:36:34 +02:00
|
|
|
cursor = Transaction().cursor
|
2012-09-24 22:17:54 +02:00
|
|
|
table = TableHandler(cursor, cls, module_name)
|
2012-05-14 15:36:34 +02:00
|
|
|
|
2012-09-24 22:17:54 +02:00
|
|
|
super(DashboardAction, cls).__register__(module_name)
|
2012-05-14 15:36:34 +02:00
|
|
|
|
|
|
|
|
# Migration from 2.4: drop required on sequence
|
|
|
|
|
table.not_null_action('sequence', action='remove')
|
2013-09-06 22:34:16 +02:00
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def order_sequence(tables):
|
|
|
|
|
table, _ = tables[None]
|
2015-07-13 23:58:23 +02:00
|
|
|
return [Case((table.sequence == Null, 0), else_=1), table.sequence]
|