Reviewers: ,


Please review this at http://codereview.tryton.org/484002/

Affected files:
  M tryton/gui/window/view_form/screen/screen.py
  M tryton/gui/window/view_form/view/form.py
  M tryton/gui/window/view_form/view/list_gtk/parser.py


Index: tryton/gui/window/view_form/screen/screen.py
===================================================================

--- a/tryton/gui/window/view_form/screen/screen.py
+++ b/tryton/gui/window/view_form/screen/screen.py
@@ -18,7 +18,8 @@
 from tryton.jsonrpc import JSONEncoder
 from tryton.common.domain_parser import DomainParser
 from tryton.common import RPCExecute, RPCException, MODELACCESS, \
-    node_attributes
+    node_attributes, sur
+from tryton.action import Action


 class Screen(SignalEvent):
@@ -796,3 +797,23 @@
         if self.model_name == 'res.request':
             from tryton.gui.main import Main
             Main.get_main().request_set()
+
+    def button(self, button):
+        'Execute button on the current record'
+        if button.get('confirm', False) and not sur(button['confirm']):
+            return
+        record = self.current_record
+        record.save(force_reload=False)
+        context = record.context_get()
+        try:
+ action_id = RPCExecute('model', self.model_name, button['name'],
+                [record.id], context=context)
+        except RPCException:
+            action_id = None
+        if action_id:
+            Action.execute(action_id, {
+                    'model': self.model_name,
+                    'id': record.id,
+                    'ids': [record.id],
+                    }, context=context)
+        self.reload([record.id], written=True)

Index: tryton/gui/window/view_form/view/form.py
===================================================================

--- a/tryton/gui/window/view_form/view/form.py
+++ b/tryton/gui/window/view_form/view/form.py
@@ -4,10 +4,7 @@
 from functools import reduce
 import gtk
 import gettext
-import tryton.common as common
 from interface import ParserView
-from tryton.action import Action
-from tryton.common import RPCExecute, RPCException

 _ = gettext.gettext

@@ -172,37 +169,9 @@

     def button_clicked(self, widget):
         record = self.screen.current_record
-        attrs = widget.attrs
         fields = self.get_fields()
-        if record.validate(fields):
-            # Don't reload as it will be done after the RPC call
-            record.save(force_reload=False)
-            if not attrs.get('confirm', False) or \
-                    common.sur(attrs['confirm']):
-                button_type = attrs.get('type', 'object')
-                context = record.context_get()
-                if button_type == 'object':
-                    try:
-                        RPCExecute('model', self.screen.model_name,
-                            attrs['name'], [record.id], context=context)
-                    except RPCException:
-                        pass
-                elif button_type == 'action':
-                    action_id = None
-                    try:
-                        action_id = RPCExecute('model', 'ir.action',
-                            'get_action_id', int(attrs['name']),
-                            context=context)
-                    except RPCException:
-                        pass
-                    if action_id:
-                        Action.execute(action_id, {
-                            'model': self.screen.model_name,
-                            'id': record.id,
-                            'ids': [record.id],
-                            }, context=context)
-                else:
-                    raise Exception('Unallowed button type')
-                self.screen.reload([record.id], written=True)
+        if not record.validate(fields):
+            self.screen.display()
+            return
         else:
-            self.screen.display()
+            self.screen.button(widget.attrs)

Index: tryton/gui/window/view_form/view/list_gtk/parser.py
===================================================================

--- a/tryton/gui/window/view_form/view/list_gtk/parser.py
+++ b/tryton/gui/window/view_form/view/list_gtk/parser.py
@@ -28,7 +28,6 @@
 from tryton.common.cellrendererinteger import CellRendererInteger
 from tryton.common.cellrendererfloat import CellRendererFloat
 from tryton.common.cellrendererbinary import CellRendererBinary
-from tryton.action import Action
 from tryton.translate import date_format
 from tryton.common import RPCExecute, RPCException

@@ -945,38 +944,7 @@
         if state_changes.get('invisible') \
                 or state_changes.get('readonly'):
             return True
-
-        self.screen.current_record = record
-        obj_id = self.screen.save_current()
-        if obj_id:
-            if not self.attrs.get('confirm', False) or \
-                    common.sur(self.attrs['confirm']):
-                button_type = self.attrs.get('type', 'object')
-                ctx = record.context_get()
-                if button_type == 'object':
-                    try:
-                        RPCExecute('model', self.screen.model_name,
-                            self.attrs['name'], [obj_id], context=ctx)
-                    except RPCException:
-                        pass
-                elif button_type == 'action':
-                    try:
-                        action_id = RPCExecute('model', 'ir.action',
-                            'get_action_id', int(self.attrs['name']),
-                            context=ctx)
-                    except RPCException:
-                        action_id = None
-                    if action_id:
-                        Action.execute(action_id, {
-                            'model': self.screen.model_name,
-                            'id': obj_id,
-                            'ids': [obj_id],
-                            }, context=ctx)
-                else:
-                    raise Exception('Unallowed button type')
-                self.screen.reload([obj_id], written=True)
-            else:
-                self.screen.display()
+        self.screen.button(self.attrs)

 CELLTYPES = {
     'char': Char,



--
[email protected] mailing list

Reply via email to