Search code examples
pythonxmlodoo

how to replace record name in specific action in odoo?


i have a model called patient contains all patient data, i need to add another menu for some group of users that open the model but without any sesnative data such as Name, but it's by default the _rec_name of the model, how to hide the name of the patient on specific action to be another field or static string like "Patient"

any help will be appreciated...


Solution

  • I do it by overriding the name_get method and add the new condition that will return another name if I'm using the model in my new menu which appears only for the new group

    def name_get(self):
        result = []
        if not self.env.user.has_group('pl_analytic.group_pl_analytic'):
            for patient in self:
                name = patient.full_name
                result.append((patient.id, name))
        else:
            for patient in self:
                result.append((patient.id, patient.identification_code))
        return result
    

    thanks for all