i have a field grade_ids one2many with a model student.subject.grade
i want in method write in model (student.stage.history) create a
history student for a education_estate
i want when a change eductaion_estate create in model (student.stage.history) a grade_ids but after create put old_grade in archive but save old_grade in history before archive
grade_ids = fields.One2many(
'student.subject.grade', 'student_id',
domain="[('education_stage', '=', education_stage)]",
string='Grades', tracking=True)
@api.model
def write(self, vals):
# if 'grade_ids' in vals:
if 'education_stage' in vals:
old_stage = student.education_stage
old_stage_label = dict(self._fields['education_stage'].selection).get(old_stage)
new_stage = vals.get('education_stage')
old_subjects = self.env['school.subject'].search(
[('education_stage', '=', student.education_stage)])
new_subjects = self.env['school.subject'].search(
[('education_stage', '=', new_stage)]
old_grades = student.grade_ids.filtered(lambda g: g.education_stage == old_stage)
# print("Old Grades:", old_grades) old_grades
if old_grades:
history_record = self.env['student.stage.history'].create(
{
'student_id' : student.id,
'old_stage' : old_stage_label,
'education_stage': new_stage,
'date' : fields.Datetime.now(),
'grade_ids' : [(6, 0, old_grades.ids)],
'old_subject_ids': [(6, 0, student.grade_ids.mapped('subject_id.id'))],
# 'old_subject_ids': [(6, 0, old_subjects.ids)]
# 'new_subject_ids': [(6, 0, new_subjects.ids)],
}
)
old_grades.write({'active': False})
res = super(SchoolStudent, self).write(vals)
return res
my code this he create a model history but old grade dont visible in history
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Dự án
- MRP
Câu hỏi này đã bị gắn cờ
11651
Lượt xem
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng ký