跳至內容
選單
此問題已被標幟
3 回覆
2218 瀏覽次數

class Partner(models.Model):

    _description = 'Contact'

    _inherit = ['format.address.mixin', 'avatar.mixin']

    _name = "res.partner"

    _order = "complete_name ASC, id DESC"

    _rec_names_search = ['complete_name', 'email', 'ref', 'vat', 'company_registry']


Help me in replacing complete_name or display_name in Contacts to be name field only.

頭像
捨棄
最佳答案

Hi,
You have to inherit and modify the _compute_display_name function for this.

See:  https://www.youtube.com/watch?v=5ga7dlVoZ2M

Thanks

頭像
捨棄
最佳答案

Try inherit and overide the _rec_names_search

class ResPartner(models.Model):
​_inherit = 'res.partner'
​_rec_names_search = ['name']


頭像
捨棄
作者 最佳答案
class ResPartner(models.Model):
    _inherit = 'res.partner'

    def name_get(self):
        result = []
        for partner in self:
            name = partner.name
            result.append((partner.id, name))
        return result

This code isn't helping either

頭像
捨棄

I am unsure what you exactly want.

from odoo import models, fields?, api?

class ResPartner(models.Model):
_inherit = 'res.partner'

def name_get(self):
result = super(ResPartner, self).name_get() # Call the original method to preserve existing functionality
custom_result = []
for partner in self:
name = partner.name
custom_result.append((partner.id, name))

# Combine the original result with the custom one if necessary
result.extend(custom_result)
return result

There is a basefield for "display_name", there is a basefield for "complete_name", and there is a basefield for "name".

We are trying to extract "name" from "ir.model.fields"? In the "ir.model" > "res.partner" model?

相關帖文 回覆 瀏覽次數 活動
3
7月 25
2045
1
6月 25
2415
2
5月 25
2014
1
5月 25
1222
1
5月 25
1475