Skip to content

Instantly share code, notes, and snippets.

@repodevs
Created September 6, 2017 05:48
Show Gist options
  • Save repodevs/e77ec4391c3059a0f0639bc53de76cf0 to your computer and use it in GitHub Desktop.
Save repodevs/e77ec4391c3059a0f0639bc53de76cf0 to your computer and use it in GitHub Desktop.
odoo name_get inherit
# -*- coding: utf-8 -*-
# © 2017 Niaga Solution - Edi Santoso <[email protected]>
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import api, models
class Contact(models.Model):
_inherit = 'res.partner'
@api.multi
def name_get(self):
res = super(Contact, self).name_get()
res_dict = dict(res)
for record in self:
if record.unit_id:
res_dict[record.id] = "(%s) %s" % (record.unit_id.code, record.name)
return res_dict.items()
@repodevs
Copy link
Author

repodevs commented Sep 6, 2017

@mhdsyarif coba ini mas

from odoo import api, models

class Contact(models.Model):
    _inherit = 'res.partner'
     
    @api.multi
    def name_get(self):
        res = super(Contact, self).name_get()
        res_dict = dict(res)
        for record in self:
            if record.email:
                res_dict[record.id] = "%s / %s" % (record.name, record.email)
        return res_dict.items()

ini akan menampilkan
nama -> Jikas User tidak mempunyai e-mail
nama / [email protected] -> Jika user punya e-mail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment