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
- Kirjanpito
- Varastointi
- PoS
- Projekti
- MRP
Tämä kysymys on merkitty
11650
Näkymät
Nautitko keskustelusta? Älä vain lue, vaan osallistu!
Luo tili jo tänään nauttiaksesi yksinoikeusominaisuuksista ja osallistuaksesi mahtavaan yhteisöömme!
Rekisteröidy