Skip to content
  • Categories
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse

Odoo 中文社区

  1. Home
  2. Categories
  3. Odoo 新手求助
  4. 单击一个按钮弹出一个form表单,怎么不刷新原表单?

单击一个按钮弹出一个form表单,怎么不刷新原表单?

Scheduled Pinned Locked Moved Odoo 新手求助
14 Posts 4 Posters 11.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    winbo
    wrote on last edited by
    #1

    一个表单页面formA 上有个按钮,点击按钮弹出一个formB表单,但是我原来的表单formA好像是刷新了还是怎么了,获取了数据库最新的一条记录出来,怎么回事?我不要刷新原表单formA,怎么处理?
    按钮:
    《button name="draft_force_assign" string="收货" type="object" class="oe_highlight" groups="base.group_user"/》

    1 Reply Last reply
    0
    • W Offline
      W Offline
      winbo
      wrote on last edited by
      #2

      我在按钮的事件是返回一个formB表单:
      def draft_force_assign_winbo(self, cr, uid, ids, context=None):
      print '--11111111111------------'
      if context is None:
      context = {}
      """Open the partial picking wizard"""

          dict2 = {
              'view_type': 'form',
              'view_mode': 'form',
              'res_model': 'stock.partial.picking',
              'type': 'ir.actions.act_window',
              'target': 'new',
              'context': context,
              'nodestroy': True,
          }
      
          return dict2
      
      1 Reply Last reply
      0
      • W Offline
        W Offline
        winbo
        wrote on last edited by
        #3

        已经找到原因,原来这个按钮先执行了默认的create方法,所以才感觉刷新了,怎么让他不要执行create方法呢?

        1 Reply Last reply
        0
        • 萧 Offline
          萧 Offline
          萧云飞
          wrote on last edited by
          #4

          我也遇到过类似需求,也发现这个问题,不过odoo框架机制是这样子设置的。我没有找到类似方法,不过我想了下,form表单里面可以自定义html标签,你再插入js,js里面再以json-rpc的方式提交,或者直接调用call方法,或许是一个解决方法。我没有试,你可以试试

          W 1 Reply Last reply
          0
          • 萧 萧云飞

            我也遇到过类似需求,也发现这个问题,不过odoo框架机制是这样子设置的。我没有找到类似方法,不过我想了下,form表单里面可以自定义html标签,你再插入js,js里面再以json-rpc的方式提交,或者直接调用call方法,或许是一个解决方法。我没有试,你可以试试

            W Offline
            W Offline
            winbo
            wrote on last edited by
            #5

            @萧云飞 我试过用js调用后台方法,但怎么搞都抱错,openerp的js很难理解。我是这样处理的重写了create方法就好了

            萧 2 Replies Last reply
            0
            • W winbo

              @萧云飞 我试过用js调用后台方法,但怎么搞都抱错,openerp的js很难理解。我是这样处理的重写了create方法就好了

              萧 Offline
              萧 Offline
              萧云飞
              wrote on last edited by
              #6

              @winbo 👏🏻

              1 Reply Last reply
              0
              • W winbo

                @萧云飞 我试过用js调用后台方法,但怎么搞都抱错,openerp的js很难理解。我是这样处理的重写了create方法就好了

                萧 Offline
                萧 Offline
                萧云飞
                wrote on last edited by
                #7

                @winbo 我想问下,你重新了create方法,是在create方法里面直接调用draft_force_assign_winbo()这个方法吗?今天我试了下,不行呢

                1 Reply Last reply
                0
                • W Offline
                  W Offline
                  winbo
                  wrote on last edited by
                  #8

                  create 方法里面不需要调用 你自己的方法,他会执行完create 方法继续执行你的这个方法@萧云飞

                  萧 1 Reply Last reply
                  0
                  • W winbo

                    create 方法里面不需要调用 你自己的方法,他会执行完create 方法继续执行你的这个方法@萧云飞

                    萧 Offline
                    萧 Offline
                    萧云飞
                    wrote on last edited by
                    #9

                    那它还是会调用create方法,创建实例,然后刷新当前表单的数据的。@winbo, 能看下,你特殊处理的那段代码么?

                    W 1 Reply Last reply
                    0
                    • 萧 萧云飞

                      那它还是会调用create方法,创建实例,然后刷新当前表单的数据的。@winbo, 能看下,你特殊处理的那段代码么?

                      W Offline
                      W Offline
                      winbo
                      wrote on last edited by
                      #10

                      @萧云飞 def create(self, cr, uid, vals, context=None):
                      print "==============winbo=========create"
                      print vals
                      super(stock_picking_in_winbo, self).write(cr, uid, picking_id, vals, context=context)
                      # self.draft_force_assign_winbo(self, cr, uid,picking_id)

                          return picking_id
                      
                      
                      def draft_force_assign_winbo(self, cr, uid, ids, context=None):
                      
                          if context is None:
                              context = {}
                          stock_obj = self.browse(cr, uid, ids)
                      
                          """Open the partial picking wizard"""
                          context.update({
                              'active_model': self._name,
                              'active_ids': ids,
                              'active_id': len(ids) and ids[0] or False,
                              'ref_id': 13
                          })
                      
                          mod_obj = self.pool.get('ir.model.data')
                          res = mod_obj.get_object_reference(cr, uid, 'starmerx_stock', 'starmerx_stock_partial_picking_form')
                          # raise osv.except_osv(_('无法保存 !'), _('字段值有错误!'))
                          return {
                              'view_type': 'form',
                              'view_mode': 'form',
                              'view_id': [res and res[1] or False],
                              'res_model': 'stock.partial.picking',
                              'type': 'ir.actions.act_window',
                              'target': 'new',
                              'context': context,
                              'nodestroy': True,
                          }
                      

                      我的这个场景可能跟你的不一样,我之前也以为要在create里面调用我的方法,但其实不用

                      萧 1 Reply Last reply
                      0
                      • JoshuaJ Offline
                        JoshuaJ Offline
                        Joshua
                        管理员
                        wrote on last edited by
                        #11

                        如果你的按钮的类型是object,在点击的时候会调用read方法来刷新你的FormA,如果你的按钮类型是action,则可以不刷新FormA,也能弹出FormB。

                        例如:

                        <button name="%(action_view_sale_advance_payment_inv)d" string="Create Invoice"
                                                type="action" class="btn-primary"
                                                attrs="{'invisible': [('invoice_status', '!=', 'to invoice')]}"/>
                        
                        

                        【上海先安科技】(joshua AT openerp.cn),欢迎关注公众号:openerp_cn

                        D 萧 2 Replies Last reply
                        1
                        • JoshuaJ Joshua

                          如果你的按钮的类型是object,在点击的时候会调用read方法来刷新你的FormA,如果你的按钮类型是action,则可以不刷新FormA,也能弹出FormB。

                          例如:

                          <button name="%(action_view_sale_advance_payment_inv)d" string="Create Invoice"
                                                  type="action" class="btn-primary"
                                                  attrs="{'invisible': [('invoice_status', '!=', 'to invoice')]}"/>
                          
                          
                          D Offline
                          D Offline
                          digitalsatori
                          管理员
                          wrote on last edited by
                          #12

                          @Joshua 👍

                          【上海先安科技】(tony AT openerp.cn)

                          1 Reply Last reply
                          0
                          • W winbo

                            @萧云飞 def create(self, cr, uid, vals, context=None):
                            print "==============winbo=========create"
                            print vals
                            super(stock_picking_in_winbo, self).write(cr, uid, picking_id, vals, context=context)
                            # self.draft_force_assign_winbo(self, cr, uid,picking_id)

                                return picking_id
                            
                            
                            def draft_force_assign_winbo(self, cr, uid, ids, context=None):
                            
                                if context is None:
                                    context = {}
                                stock_obj = self.browse(cr, uid, ids)
                            
                                """Open the partial picking wizard"""
                                context.update({
                                    'active_model': self._name,
                                    'active_ids': ids,
                                    'active_id': len(ids) and ids[0] or False,
                                    'ref_id': 13
                                })
                            
                                mod_obj = self.pool.get('ir.model.data')
                                res = mod_obj.get_object_reference(cr, uid, 'starmerx_stock', 'starmerx_stock_partial_picking_form')
                                # raise osv.except_osv(_('无法保存 !'), _('字段值有错误!'))
                                return {
                                    'view_type': 'form',
                                    'view_mode': 'form',
                                    'view_id': [res and res[1] or False],
                                    'res_model': 'stock.partial.picking',
                                    'type': 'ir.actions.act_window',
                                    'target': 'new',
                                    'context': context,
                                    'nodestroy': True,
                                }
                            

                            我的这个场景可能跟你的不一样,我之前也以为要在create里面调用我的方法,但其实不用

                            萧 Offline
                            萧 Offline
                            萧云飞
                            wrote on last edited by
                            #13

                            @winbo 在 单击一个按钮弹出一个form表单,怎么不刷新原表单? 中说:

                            picking

                            谢谢

                            1 Reply Last reply
                            0
                            • JoshuaJ Joshua

                              如果你的按钮的类型是object,在点击的时候会调用read方法来刷新你的FormA,如果你的按钮类型是action,则可以不刷新FormA,也能弹出FormB。

                              例如:

                              <button name="%(action_view_sale_advance_payment_inv)d" string="Create Invoice"
                                                      type="action" class="btn-primary"
                                                      attrs="{'invisible': [('invoice_status', '!=', 'to invoice')]}"/>
                              
                              
                              萧 Offline
                              萧 Offline
                              萧云飞
                              wrote on last edited by
                              #14

                              @Joshua 谢谢你的讲解,这个action在某些场景不适用。某些条件成立时,才弹出一个窗口,其它条件就执行另外的代码;或者根据不同的条件,处理不同的数据后,弹出不同的窗口(可以定义多个button,但是attrs条件框处理能力毕竟有限)

                              1 Reply Last reply
                              0

                              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                              With your input, this post could be even better 💗

                              Register Login
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Tags
                              • Popular
                              • Users
                              • Groups