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

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

頭像
捨棄
作者 最佳答案

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]


頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
3
9月 24
1316
0
12月 23
1272
1
7月 25
5704
1
12月 21
5038
0
10月 21
2869