Skip to content

Instantly share code, notes, and snippets.

@dreispt
Last active September 8, 2020 16:27
Show Gist options
  • Save dreispt/e04586c670944dbbfe5dadca29ebb4bb to your computer and use it in GitHub Desktop.
Save dreispt/e04586c670944dbbfe5dadca29ebb4bb to your computer and use it in GitHub Desktop.
Example extending name_get
from odoo import fields, models
class Partner(models.Model):
_inherit = "res.partner"
def name_get(self):
orig_res = super().name_get()
# orig_names = {rec_id: rec_name for rec_id, rec_name in orig_res}
orig_names = dict(orig_res) # even simpler
res = []
for record in self:
# naive, ignores super():
name = record.name
# optimized, uses super():
name = orig_names[record.id]
city = record.city
state = record.state_id.name
display_name = "%s (%s, %s)" % (name, city, state)
res.append((record.id, display_name))
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment