Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
6004 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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)


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 7 24
7716
2
thg 5 23
7336
1
thg 12 22
3681
1
thg 3 22
2720
0
thg 3 22
101