تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
3651 أدوات العرض

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
سبتمبر 24
1354
0
ديسمبر 23
1295
1
يوليو 25
5745
1
ديسمبر 21
5082
0
أكتوبر 21
2901