File: tree.py

package info (click to toggle)
tinyerp-client 3.4.2-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,832 kB
  • ctags: 1,024
  • sloc: python: 7,566; sh: 2,253; makefile: 81
file content (208 lines) | stat: -rw-r--r-- 6,957 bytes parent folder | download
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
##############################################################################
#
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
#                    Fabien Pinckaers <fp@tiny.Be>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
##############################################################################

import gtk
from gtk import glade
import gettext
import xmlrpclib

import common
import service
import view_tree
import rpc
import options

class tree(object):
	def __init__(self, view, model, res_id=False, domain=[], context={}):
		self.glade = glade.XML(common.terp_path("terp.glade"),'win_tree_container',gettext.textdomain())
		self.widget = self.glade.get_widget('win_tree_container')
		self.widget.show_all()
		self.model = view['model']
		self.domain2 = domain
		if view.get('field_parent', False):
			self.domain = []
		else:
			self.domain = domain
		self.view = view

		vp = self.glade.get_widget('main_tree_sw')
		ids = rpc.session.rpc_exec_auth('/object', 'execute', self.model, 'search', self.domain2)
		self.tree_res = view_tree.view_tree(view, ids, res_id, True, context=context)
		self.tree_res.view.connect('row-activated', self.sig_open)
		#self.tree_res.view.connect('row-activated', self.sig_open)
		sel = self.tree_res.view.get_selection()
		sel.connect('changed', self.expand_one)

		self.name = self.tree_res.name
		vp.add(self.tree_res.widget_get())
		
		wid = self.glade.get_widget('widget_vbox')
		if options.options['client.modepda']:
			wid.hide()
		else:
			wid.show()

		widget_sc = self.glade.get_widget('win_tree_sc')

		imagename = 'tinyerp.png'

		
		widget_sc.connect('row-activated', self.sc_go)
		self.tree_sc = view_tree.view_tree_sc(widget_sc, self.model)
		self.handlers = {
			'but_reload': (_('Reload'),self.sig_reload),
			'but_switch': (_('Switch View'),self.sig_edit),
			'but_chroot': (_('Changt root'),self.sig_chroot),
			'but_open': (_('Open'),self.sig_open),
			'but_action': (_('Open'),self.sig_action),
			'but_print': (_('Print'),self.sig_print),
			'but_print_html': (_('Print'),self.sig_print_html),
			'but_close': (_('Close'),self.sig_close)
		}
		dict = {
			'on_but_sc_go_clicked': self.sc_go,
			'on_but_sc_add_clicked': self.sc_add,
			'on_but_sc_del_clicked': self.sc_del
		}
		for signal in dict:
			self.glade.signal_connect(signal, dict[signal])

	def expand_one(self, selection):
		model,iter = selection.get_selected_rows()
		self.tree_res.view.expand_row(iter[0], False)

	def sig_print_html(self, widget=None, keyword='client_print_multi', id=None):
		self.sig_action(keyword='client_print_multi', report_type='html')

	def sig_print(self, widget=None, keyword='client_print_multi', id=None):
		self.sig_action(keyword='client_print_multi')

	def sig_action(self, widget=None, keyword='tree_but_action', id=None, report_type='pdf'):
		ids = self.ids_get()
		
		if not id and ids and len(ids):
			id = ids[0]
		if id:
			obj = service.LocalService('action.main')
			obj.exec_keyword(keyword, {'model':self.model, 'id':id,
							  'ids':ids, 'report_type':report_type})
		else:
			common.message(_('No resource selected!'))

	def sig_reload(self, widget=None):
		self.tree_res.reload()

	def sig_open(self, widget=None, *args):
		self.sig_action(widget, 'tree_but_open' )

	def sig_remove(self, widget=None):
		ids = self.ids_get()
		if len(ids):
			if common.sur(_('Are you sure you want\nto remove this record?')):
				try:
					rpc.session.rpc_exec_auth('/object', 'execute', self.model, 'unlink', ids)
					self.sig_reload()
				except xmlrpclib.Fault, err:
					common.message(_('Error removing resource!'))

	# TODO: improve with domain expr
	def sig_chroot(self, widget=None):
		ids = self.ids_get()
		if len(ids) and self.domain:
			id = ids[0]
			datas = {'domain_field': self.domain[0][0], 'domain_value': id[0], 'res_id':id[0]}
			obj = service.LocalService('gui.window')
			obj.create(self.view, self.model, id[0], (self.domain[0],id[0]) )
		else:
			common.message(_('Unable to chroot: no tree resource selected'))

	def sig_new(self, widget=None):
		#datas = {'res_model':self.model, 'domain_field': self.domain[0], 'domain_value': self.id_get(), 'res_id':None}
#		domain = self.domain
#		if self.domain:
#			id = self.id_get()
#			if id:
#				domain=(domain[0],id)
		obj = service.LocalService('gui.window')
		obj.create(None, self.model, None, self.domain)

	def sig_edit(self, widget=None):
		ids = self.ids_get()
		if len(ids):
			obj = service.LocalService('gui.window')
			obj.create(None, self.model, ids[0], self.domain)
		else:
			common.message(_('No resource selected!'))

	def domain_id_get(self, tree=False):
		filter = []
		if self.domain and self.view.get('field_parent', False):
			filter = self.domain
		res = rpc.session.rpc_exec_auth('/object', 'execute', self.model, 'search', filter)
		return res

	def sig_printscreen(self, widget=None):
		ids = self.tree_res.ids
		pass

	def sc_del(self, widget):
		id = self.tree_sc.sel_id_get()
		if id!=None:
			sc_id = int(self.tree_sc.value_get(2))
			rpc.session.rpc_exec_auth('/object', 'execute', 'ir.ui.view_sc', 'unlink', [sc_id])
		self.tree_sc.update()

	def sc_add(self, widget):
		ids = self.tree_res.sel_ids_get()
		if len(ids):
			res = rpc.session.rpc_exec_auth('/object', 'execute', self.model, 'name_get', ids, rpc.session.context)
			for (id,name) in res:
				uid = rpc.session.uid
				rpc.session.rpc_exec_auth('/object', 'execute', 'ir.ui.view_sc', 'create', {'resource':self.model, 'user_id':uid, 'res_id':id, 'name':name})
		self.tree_sc.update()

	def sc_go(self, widget=None, *args):
		id = self.tree_sc.sel_id_get()
		if id!=None:
			self.sig_action(None, 'tree_but_open', id)

	def ids_get(self):
		res = self.tree_res.sel_ids_get()
		return res

	def id_get(self):
		try:
			return self.search[self.search_pos]
		except IndexError:
			return None

	def destroy(self):
		pass

	def sig_close(self, urgent=False):
		return True