import re with open('addons/education_lms/security/security.xml', 'r') as f: text = f.read() # Replace .mapped('field_name').ids with .field_name.ids text = text.replace("user.student_ids.mapped('program_id').ids", "user.student_ids.program_id.ids") text = text.replace("user.student_ids.mapped('academic_year_id').ids", "user.student_ids.academic_year_id.ids") text = text.replace("user.student_ids.mapped('academic_term_id').ids", "user.student_ids.academic_term_id.ids") text = text.replace("user.student_ids.mapped('batch_id').ids", "user.student_ids.batch_id.ids") with open('addons/education_lms/security/security.xml', 'w') as f: f.write(text)