Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.entry = gtk.combo_box_entry_new_text()
self.entry.child.set_editable(True)
self.entry.child.set_property('activates_default', True)
self.entry.child.connect('key_press_event', self.sig_key_press)
self.entry.child.connect('key_press_event', self.on_change)
self.entry.set_focus_chain([self.entry.child])
self._selection = {}
selection = self.attrs.get('selection', [])
if 'relation' in self.attrs:
if not self.attrs.get('domain'):
domain = []
else:
domain = PYSONDecoder(rpc.CONTEXT).decode(self.attrs['domain'])
try:
result = rpc.execute('model', self.attrs['relation'],
'search_read', domain, 0, None, None,
['rec_name'], rpc.CONTEXT)
selection = [(x['id'], x['rec_name']) for x in result]
except TrytonServerError, exception:
common.process_exception(exception)
selection = []
else:
if not isinstance(selection, (list, tuple)):
try:
selection = rpc.execute('model',
self.attrs['model'], selection, rpc.CONTEXT)
except TrytonServerError, exception:
common.process_exception(exception)
selection = []
selection.sort(key=operator.itemgetter(1))
self.attrs['selection'] = selection
def run(self, datas=None):
if datas is None:
datas = {}
while True:
res = self.dia.run()
self.screen.current_view.set_value()
if self.screen.current_record.validate() \
or (res<0) or (self.states[res]=='end'):
break
self.screen.display()
if CONFIG['client.save_width_height']:
width, height = self.dia.get_size()
if (width, height) != (self.widget_width, self.widget_height):
try:
rpc.execute('model', 'ir.action.wizard_size', 'set_size',
self.action, self.screen.model_name, width, height,
rpc.CONTEXT)
except TrytonServerError:
pass
if res < len(self.states) and res >= 0:
datas.update(self.screen.get())
self.dia.hide()
self.parent.present()
return self.states[res], datas
else:
self.dia.hide()
self.parent.present()
return False
if 'relation' in self.fields_type[field]:
try:
result = rpc.execute('model',
self.fields_type[field]['relation'],
'search_read',
self.fields_type[field].get('domain', []),
0, None, None,
['rec_name'], rpc.CONTEXT)
selection = [(x['id'], x['rec_name']) for x in result]
except Exception:
selection = []
else:
if not isinstance(self.fields_type[field]['selection'],
(list, tuple)):
try:
selection = rpc.execute('model',
self.view['model'],
self.fields_type[field]['selection'],
rpc.CONTEXT)
except Exception:
selection = []
self.fields_type[field]['selection'] = selection
elif field_type in ('float', 'numeric'):
digits = self.fields_type[field].get('digits', (16, 2))
for obj in res_ids:
if isinstance(digits, str):
digits = PYSONDecoder(obj).decode(digits)
obj[field] = locale.format('%.' + str(digits[1]) + 'f',
round(obj[field] or 0.0, digits[1]), True)
elif field_type in ('integer',):
for obj in res_ids:
obj[field] = locale.format('%d', obj[field] or 0, True)
sdt = szone.localize(obj[field], is_dst=True)
ldt = sdt.astimezone(lzone)
obj[field] = ldt
except Exception:
pass
obj[field] = common.datetime_strftime(obj[field],
display_format)
elif field_type in ('many2one', 'one2one'):
for obj in res_ids:
if obj[field]:
obj[field] = obj[field + '.rec_name']
elif field_type in ('selection'):
selection = self.fields_type[field]['selection']
if 'relation' in self.fields_type[field]:
try:
result = rpc.execute('model',
self.fields_type[field]['relation'],
'search_read',
self.fields_type[field].get('domain', []),
0, None, None,
['rec_name'], rpc.CONTEXT)
selection = [(x['id'], x['rec_name']) for x in result]
except Exception:
selection = []
else:
if not isinstance(self.fields_type[field]['selection'],
(list, tuple)):
try:
selection = rpc.execute('model',
self.view['model'],
self.fields_type[field]['selection'],
rpc.CONTEXT)
def __init__(self, model, window, res_id=False, view_id=False, domain=None,
context=None, name=False):
super(Tree, self).__init__()
if domain is None:
domain = {}
if context is None:
context = {}
ctx = {}
ctx.update(context)
ctx.update(rpc.CONTEXT)
if view_id:
try:
view_base = rpc.execute('model', 'ir.ui.view', 'read', view_id,
['model', 'type'], ctx)
except Exception, exception:
common.process_exception(exception, window)
raise
try:
view = rpc.execute('model', view_base['model'],
'fields_view_get', view_id, view_base['type'], ctx)
except Exception, exception:
common.process_exception(exception, window)
raise
else:
try:
view = rpc.execute('model', model, 'fields_view_get', False,
'tree', ctx)
except Exception, exception:
common.process_exception(exception, window)
def _read(self, ids, fields):
ctx = {}
ctx.update(self.context)
ctx.update(rpc.CONTEXT)
res_ids = []
if ids:
args = ('model', self.view['model'], 'read', ids, fields, ctx)
try:
res_ids = rpc.execute(*args)
for obj_id in ids:
if obj_id in self.to_reload:
self.to_reload.remove(obj_id)
except Exception, exception:
for obj_id in ids:
val = {'id': obj_id}
for field in fields:
if field in self.fields_type \
and self.fields_type[field]['type'] \
in ('one2many', 'many2many'):
val[field] = []
else:
val[field] = ''
res_ids.append(val)
if obj_id not in self.to_reload:
self.to_reload.append(obj_id)
args = ('model', self.model, 'search', self.domain2, 0, None,
None, ctx)
ids = rpc.execute(*args)
except Exception, exception:
ids = common.process_exception(exception, self.window, *args)
if not ids:
return
if self.tree_res.toolbar and not CONFIG['client.modepda']:
for child in self.toolbar.get_children():
self.toolbar.remove(child)
ctx = {}
ctx.update(rpc.CONTEXT)
try:
args = ('model', self.view['model'], 'read', ids,
['name', 'icon'], ctx)
results = rpc.execute(*args)
except Exception, exception:
results = common.process_exception(exception, self.window, *args)
if not results:
return
results.sort(lambda x, y: cmp(ids.index(x['id']),
ids.index(y['id'])))
radiotb = None
for res in results:
common.ICONFACTORY.register_icon(res['icon'])
radiotb = gtk.RadioToolButton(radiotb, res['icon'])
radiotb.set_label(res['name'])
radiotb.show_all()
radiotb.set_data('id', res['id'])
radiotb.connect('clicked', self.menu_main_clicked)
self.menu_main_clicked(radiotb, focus=False)
self.toolbar.insert(radiotb, -1)
def sc_del(self, widget):
obj_id = self.tree_sc.sel_id_get()
if obj_id is not None:
sc_id = int(self.tree_sc.value_get(2))
try:
rpc.execute('model', 'ir.ui.view_sc', 'delete', sc_id,
rpc.CONTEXT)
except Exception, exception:
common.process_exception(exception, self.window)
self.tree_sc.update()