Last active
September 8, 2020 16:27
-
-
Save dreispt/e04586c670944dbbfe5dadca29ebb4bb to your computer and use it in GitHub Desktop.
Example extending name_get
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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