Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
6044 Vizualizări

i created a transient model and when i click save button it should be saved in another model.

how to save it any idea

my transient model

from odoo import fields, models, api

class CreateExam(models.TransientModel):
_name = 'exam.wizards'
_description = 'Create exams'

std_wiz = fields.Many2one(comodel_name='std.record',string='Student')
std_subject = fields.Many2one('std.subject',string="Subject")
std_marks=fields.Float(string="Marks")



def save_btn(self):
print("saved")
return True

model that data should be saved





class Exams(models.Model):
_name = 'exams.details'
_description = 'Exams'

students = fields.One2many('exam.wizards','std_wiz', string='Students')
student_subject = fields.One2many('exam.wizards','std_subject', string='subjects')

mark = fields.Float(string="marks")


Thanks in advance

Imagine profil
Abandonează
Cel mai bun răspuns

Hi,

You can use create() method to store transient model data to another model. In your case,

self.env['exams.details'].create({
'students': self.id,
'student_subject': self.std_subject,
'mark': self.std_mark
})

It will create a record in a new model with data in the transient model. You can put it in the button action.

Regards

Imagine profil
Abandonează
Cel mai bun răspuns

First you want to define the values in a dic.

for example:
vals = {
'partner_id': receipt_rec.partner_id.id,
'title'
: receipt_rec.name,
'team_id'
: 1,
'reason_id'
: self.root_cause.id
}

then create the record in the table (model) where you want with the .create() function

self.env['stock.picking'].create(vals)


Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
2
iul. 24
7758
2
mai 23
7352
1
dec. 22
3727
1
mar. 22
2752
0
mar. 22
101