Reputation: 27
i create a button in my view, and i don't know how to open a form with ( textbox and 2 button cancel and ok ) when i click on it, because i need to put in the textbox the number of time to call copy function to copy the object
`<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>
and this is my class and my function 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()
i want just to know how to open the new form with the textbox and buttons, anyone have any idea how to do it ??
Upvotes: 0
Views: 1762
Reputation: 16733
To open a new form on button click you can change button type to action
and give your action_id
on the button name. Here is the example
<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"/>
if you do not want to change the type of button then your button method should return action. eg.
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,
}
This will help you to understand the button action.
Upvotes: 1
Reputation: 2393
Forms in OpenERP are opened by actions of type act_window
. In your case you have to create a method copy(...)
inside your object immo.personne
which returns this such an action (in the form of dictionary).
Let say that your new form with the text box and two buttons is called view_copy_multiple
. Try this code:
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,
}
Upvotes: 0