콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

Hi everyone, I have two fields related to the 'res.partner' that bring me the "child_ids" of the contacts that are invoice addresses and shipping addresses. The field works perfectly but as these addresses do not have a name as such, they only have data in the fields 'street', 'street2', 'country_id', 'state_id', 'city', and 'zip' when selecting an option they all appear as "Azure Interior - Billing Address" and "Azure Interior - Shipping Address" in this example. I need that when I select the options it shows me the information of the field 'street', 'street2' and 'city' concatenated or only the information in the field 'street' of res.partner. I attach my code and a screenshot so you can see it better:


from odoo import models, fields, api

class direcciones(models.Model):
_inherit = 'account.move'

direccion_factura = fields.Many2one('res.partner', string='Direccion de Facturacion', domain="['&','&',('is_company','=',False),('parent_id','=',partner_id),('type','=','invoice')]")

direccion_envio = fields.Many2one('res.partner', string='Direccion de Envio', domain="['&','&',('is_company','=',False),('parent_id','=',partner_id),('type','=','delivery')]")




아바타
취소
베스트 답변

Solution: Override name_get for res.partner
You can override the name_get() method only for child contacts (e.g., shipping/invoice) and fall back to default for others.
Here is code :
from odoo import models, fields, api


class ResPartner(models.Model):

    _inherit = 'res.partner'


    def name_get(self):

        result = []

        for partner in self:

            if partner.type in ['invoice', 'delivery'] and partner.parent_id:

                # Compose a custom name from address fields

                parts = [partner.street, partner.street2, partner.city]

                label = ', '.join(filter(None, parts))

                result.append((partner.id, super(ResPartner, partner).name_get()[0][1]))

        return result

i hope it is helpfull

아바타
취소
베스트 답변

Hi,


In such cases odoo provides a default function ie,name_get().By using this function you can the information of the field 'street', 'street2' and 'city'..for reference you can refer our following blogs to know more about name_get()


https://www.cybrosys.com/blog/how-to-use-of-name-get-function-in-odoo


And also you can go through our youtube video


https://www.youtube.com/watch?v=kHq6nUwEGjM



Hope it helps

아바타
취소
베스트 답변

A solution is to pass a context with the field in the QWEB XML.

The context value can then read extended in the "name_get" function on the res.partener where you can return the value in the format you need.

have a look at this for more details...  Link

I think this might also be doable via wedget

아바타
취소
관련 게시물 답글 화면 활동
0
10월 23
1170
4
5월 25
1649
0
12월 24
756
ODOO.sh 해결 완료
2
10월 24
12201
1
9월 24
1187