【问题标题】:how to open a new form when i click in a button?单击按钮时如何打开新表单?
【发布时间】:2014-04-18 21:39:45
【问题描述】:

我在视图中创建了一个按钮,当我单击它时,我不知道如何使用(文本框和 2 按钮取消和确定)打开一个表单,因为我需要在文本框中输入次数调用复制函数复制对象

    `<record id="immo_personne_form" model="ir.ui.view">
        <field name="name">immo.personne.form</field>
        <field name="model">immo.personne</field>

        <field name="arch" type="xml">
            <form string="personne" >

                      <button string="Copy" type="object" name="copy_data"/>

                <field name="Pid_ftravail" />
                <field name="id_localisation" />
                <newline/>
                <field name="matricule" />
                <newline/>
                <field name="name" />
                <field name="prenom" />
                <field name="fonction" />


            </form>
        </field>
    </record>`
            <record id="immo_personne_tree" model="ir.ui.view">
        <field name="name">immo.personne.tree</field>
        <field name="model">immo.personne</field>
        <field name="arch" type="xml">
            <tree string="personnes">
            <field name="Pid_ftravail" />
            <field name="id_localisation" />
            <field name="matricule" />
                <field name="name" />
                <field name="prenom" />
                <field name="fonction" />

            </tree>
        </field>
    </record>  


        <record id="immo_personne_form_act" model="ir.actions.act_window">


        <field name="name">Personne</field>
        <field name="res_model">immo.personne</field>
        <field name="view_mode">tree,form</field>
        <field name="type">ir.actions.act_window</field>
        <field name="view_type">form</field>
        <field name="view_id" ref="immo_personne_tree"/> 
        <field name="help" type="html">
  </field>
    </record>

这是我的课程和我的函数 copy_data

class immo_personne(osv.osv):
_name = "immo.personne"
_description = "personne" 

def copy_data(self, cr, uid, id, default=None, context=None):
   if default is None:
     default = {}
   res = 1
   idea = self.browse(cr, uid, id)
   res += int(idea.matricule)
   default['matricule'] = res
   return super(immo_personne, self).copy_data(
      cr, uid, id, default, context)    

_columns = {
            'matricule':fields.integer('Matricule',size=255,required=True),
            'name':fields.char('Nom',size=255),
            'prenom':fields.char('Prenom',size=255),
            'fonction':fields.many2one('immo.fonction', 'Fonction'),
            'Pid_ftravail' : fields.many2one('immo.ftravail' ,'Formation de travail'),

            'id_localisation':fields.many2one('immo.localisation','Localisation',domain="   [('id_ftravail','=',Pid_ftravail)]"),
            }

immo_personne() 

我只想知道如何使用文本框和按钮打开新表单,有人知道怎么做吗??

【问题讨论】:

  • 嗨,我已将我的班级添加到帖子中,感谢您回答我

标签: python button openerp


【解决方案1】:

要在单击按钮时打开新表单,您可以将按钮类型更改为action,并在按钮名称上输入您的action_id。这是一个例子

        <record id="model_action_id" model="ir.actions.act_window">
            <field name="name">Personne</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">immo.personne</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
        </record>

        <button string="%(model_action_id)d" type="action" name="copy"/>

如果您不想更改按钮的类型,那么您的按钮方法应该返回操作。例如。

def copy(self, cr, uid, ids, context):
    '''
    your code
    '''
    return {
       'name': _("personne"),
       'view_mode': 'form,tree',
       'view_type': 'form',
       'res_model': 'immo.personne',
       'type': 'ir.actions.act_window',
       'nodestroy': True,
       'target': 'new',
       'context': context,
   }

这将帮助您理解按钮操作。

【讨论】:

  • 感谢您的回答,我已经重新定义了我的方法,但是这段代码不起作用
【解决方案2】:

OpenERP 中的表单由act_window 类型的操作打开。在您的情况下,您必须在您的对象 immo.personne 中创建一个方法 copy(...) ,它会返回这样的操作(以字典的形式)。

假设您的带有文本框和两个按钮的新表单称为view_copy_multiple。试试这个代码:

def copy(self, cr, uid, ids, context=None):
       if not ids: return False
       if context is None: context = {}
       model_data_pool = self.pool.get('ir.model.data')
       view = model_data_pool.get_object(cr, uid,
                                         'immo_personne',
                                         'view_copy_multiple',
                                         context=context)
       return {
           'name': _("Copy multiple records"),
           'view_mode': 'form',
           'view_id': [view.id],
           'view_type': 'form',
           'res_model': 'immo.personne',
           'type': 'ir.actions.act_window',
           'nodestroy': True,
           'target': 'new',
           'context': context,
           'res_id': ids,
       }

【讨论】:

  • 嗨,我添加了我的类代码并且已经重新定义了我的方法,我应该怎么做作为回报?那么带有文本框和 2 个按钮的视图会打扰您吗??
猜你喜欢
  • 2014-04-07
  • 2015-08-30
  • 1970-01-01
  • 1970-01-01
  • 2012-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多