Composite Unique Key Fields

Hello everyone,

I am trying to develop a new app and one of my documents needs to have a composite unique key.

The use case is to model a document that represents the cities in Spain where a single City can have multiple Postal Codes.

This solution is good for the first time that a user enters a city

       def autoname(self):
            if not self.postal_code:
           = self.city_name
           = self.city_name +" "+ self.postal_code

Here is the desired situation and works great:

The problem is that the user can now modify the Postal Code or the Name but the document name is not changed.

Is there any standard approach for this or a better solutions that does not involve marking the fields as read only?

Thank you very much

Does anyone have an idea on this?

Name of document is set after first save. you can not change it randomly.
In your case you can search your document with both postal_code and city using search field
what is your use case ?

Another Option is Title field.
Add Title field in your document. Update it with self.city_name +" "+ self.postal_code on validate event. Also set Title Field as title. That’s how you can show title of document as per city and postal_code, but name of document will be same. Check below screen shot

1 Like

Thank you very much for your response.

That partially solves the problem as when editing the document the title will be looking good but when I am making a link to this document from another document, the main item that is in bold in the search box would be the Document Name, not the Title.

Is there any way to show the title in the search box? If this was the case I would simple leave autoname empty and use the Title Field that works perfect.


You need to rename your doc. from js can call frm.rename_doc