Skip to Content
Menu
This question has been flagged
2 Replies
5976 Views

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

Avatar
Discard
Best Answer

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

Avatar
Discard
Best Answer

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)


Avatar
Discard
Related Posts Replies Views Activity
2
Jul 24
7696
2
May 23
7327
1
Dec 22
3656
1
Mar 22
2707
0
Mar 22
101