-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.py
67 lines (53 loc) · 2.13 KB
/
action.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from lxml import etree
from trytond.pool import PoolMeta, Pool
from trytond.model import fields, ModelSQL, ModelView
from trytond.ir.action import ActionMixin
class View(metaclass=PoolMeta):
__name__ = 'ir.ui.view'
@classmethod
def get_rng(cls, type_):
rng = super().get_rng(type_)
if type_ in ('form', 'list-form'):
widgets = rng.xpath(
'//ns:define/ns:optional/ns:attribute'
'/ns:name[.="widget"]/following-sibling::ns:choice',
namespaces={'ns': 'http://relaxng.org/ns/structure/1.0'})[0]
subelem = etree.SubElement(widgets,
'{http://relaxng.org/ns/structure/1.0}value')
subelem.text = 'chart'
return rng
class Action(metaclass=PoolMeta):
__name__ = 'ir.action'
@classmethod
def get_action_values(cls, type_, action_ids, columns=None):
pool = Pool()
ActionDashboard = pool.get('babi.action.dashboard')
actions = super().get_action_values(type_, action_ids, columns)
if type_ == 'babi.action.dashboard':
boards = {x.id: x for x in ActionDashboard.browse(action_ids)}
for values in actions:
values['dashboard'] = boards[values['id']].dashboard.id
return actions
class ActionDashboard(ActionMixin, ModelSQL, ModelView):
"Action Act Dashboard"
__name__ = 'babi.action.dashboard'
dashboard = fields.Many2One('babi.dashboard', 'Dashboard', required=True,
ondelete='CASCADE')
action = fields.Many2One('ir.action', 'Action', ondelete='CASCADE')
@staticmethod
def default_type():
return 'babi.action.dashboard'
class Menu(metaclass=PoolMeta):
__name__ = 'ir.ui.menu'
@classmethod
def __setup__(cls):
super().__setup__()
cls.action.selection.append(('babi.action.dashboard', 'Dashboard'))
@classmethod
def _get_action(cls, action_id):
pool = Pool()
Action = pool.get('ir.action')
action = Action(action_id)
if action.type == 'babi.action.dashboard':
action = ActionDashboard(action_id)
return super()._get_action(action)