Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
2246 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

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

Thanks

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Try inherit and overide the _rec_names_search

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


Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất
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

Ảnh đại diện
Huỷ bỏ

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?

Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 7 25
2059
1
thg 6 25
2440
2
thg 5 25
2023
1
thg 5 25
1231
1
thg 5 25
1483