import re with open('addons/education_lms/security/security.xml', 'r') as f: text = f.read() # Replace the Course rule domain text = re.sub( r'.*?\[.*?\]', """ Student Course Access [ ('state', 'in', ['published', 'closed']), ('program_id', 'in', user.student_ids.mapped('program_id').ids), ('academic_year_id', 'in', user.student_ids.mapped('academic_year_id').ids), '|', ('term_id', '=', False), ('term_id', 'in', user.student_ids.mapped('academic_term_id').ids), '|', ('batch_id', '=', False), ('batch_id', 'in', user.student_ids.mapped('batch_id').ids), ]""", text, flags=re.DOTALL ) with open('addons/education_lms/security/security.xml', 'w') as f: f.write(text)