Yardım

0

create a compute split_name field in res_partner

Hi all.

I am loosing my hair in a so simple operation.

In ResPartner I have name like "corp_town1" , "corp_town2" 

I want to create a new compte field split_name who'll contain

 name.split('_')[0]  (only corp)


from odoo import models, fields, api


class ResPartner(models.Model):
_inherit = 'res.partner'
split_name = fields.Char(compute="_split_name", store=True)
#
@api.depends('name')
def _split_name(self):
for r in self:
if not r.name:
r.split_name=""
else:
init_name=r.name
self.split_name = init_name.split('_')[0]


Any help welcome 

regards

Avatar
Vazgeç
1 Cevap
0
En iyi cevap

HI.

I manage to create the x_split_name field with the interface

contact ->  dev tools -> view field create new:

field name :x_split_name

field_type : char

related_fiels dependancies : name

compute : 

for record in self:
     record['x_split_name'] = record.name.split('_')[0]


Avatar
Vazgeç