Hi any help please how can I return values of One2many in a new form dynamically.
I have three class I define a function where I return the values of many2many(rubrique_ids) and One2many(critere_ids) exist recently in a new form how can I return(generate) form dynamically from values of One2many fields
file xml
<button name="evaluer" string="Evaluer" type="object"/>
first class
class A(models.Model):
_name='risques.risque'
_rec_name='nom_risque'
nom_risque = fields.Char(required=True, string="Nom du Risque")
rubrique_ids = fields.Many2many('risques.rubrique', string="Rubrique", required=True)
Second class :
class B(models.Model):
_name='risques.rubrique'
_rec_name='nom_rubrique'
critere_ids = fields.One2many('risques.critere','rubrique_id',required=True, string="Critére d'évaluation")
nom_rubrique = fields.Char(string="Rubrique")
Third class
class C(models.Model):
_name='risques.critere'
_rec_name='nom_critere'
nom_critere = fields.Char(string="Nom du Critere")
note = fields.Float(string="Note", readonly=True, compute='_onchange_mesure')
rubrique_id = fields.Many2one('risque.rubrique',
string='Rubrique')
class etude(models.Model):
_name = 'etude.risque'
client = fields.Many2one('res.partner', string="Client",required=True, index=True)
risque = fields.Many2one('risques.risque', string="Risque",required=True)
def evaluer(self):
context = self._context.copy()
rubriques=self.risque.risque_id
nom_rub=[]
rubs = self.env['risques.rubrique'].browse(rubriques)
critere_etude =[]
my_vals = []
for a in enumerate(rubs):
i = a[0]
r = self.env['risques.rubrique'].search([('id','=',self.risque.risque_id[i].id)])
cr = self.risque.risque_id[i].critere
for b in enumerate(cr):
j = b[0]
critere_etude.append(cr.search([('id','=',cr[j].id)]).nom_critere)
print cr.search([('id','=',cr[j].id)]).id
nom_rub.append({'etude_id' : 1,
'rubrique_etude':r.nom_categorie,
'critere_etude':critere_etude
})
critere_etude = []
my_vals.append(nom_rub)
nom_rub = []
self.env['risque.evaluation'].create({'risque_etude': self.risque.nom_risque,
'etude': my_vals})
return {
'name': 'Evaluation',
'view_type': 'form',
'view_mode': 'tree,form',
#'views': [{'view_mode': 'form', 'view_id': 'rub_id'}],
'res_model': 'risque.evaluation',
'type': 'ir.actions.act_window',
'res_id': self.id,
#'target': 'new',
'context': context,
}
how can I return rubrique_ids and critere_ids dynamically
first of all when you search for form user this:
Now when you open the action in return if you are opening the record in one view for example in form view:
Now if you want to open the more than one record and in more than one view.
Hope this gives you an idea how to specify witch view to user: Note: for search view: