Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
2316 มุมมอง

Hello,

In my contacts I want to add a field wich combines the field  "name" of the contact and the field "zip".

Should i do that with an automated action or in any other way ?


Thank you four your help.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

You have to inherit the class and define the new field:

from odoo import fields, api, models

class ResPartner(models.Model):
_inherit = "res.partner"

​zip_name = fields.Char("Custom Name", compute='_compute_zip_name')

​@api.depends('name', 'zip')
​def _compute_zip_name(self):
​for r in self:
​r.zip_name = # the logic u want for combination


อวตาร
ละทิ้ง
ผู้เขียน

Thanks for your feedback !
I'll try this as soon as possible.

คำตอบที่ดีที่สุด

Hey Edouard,

you can approach this via automated action and concatenate that fields on creating or updating the record.

But normally automated actions are not suggested if you can code it.

Via Code you can just 

new_field = fields.Char(string="new_field", compute="_concat_name_zip")

@api.depends('name','zip')
def _concat_name_zip(self):
​for record in self:
​record.new_field = record.name + record.zip


Best Regards

อวตาร
ละทิ้ง
ผู้เขียน

Thanks for your feedback !
I'll try this as soon as possible.

Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ม.ค. 24
1156
3
ก.ย. 23
2161
Explain fields.property() แก้ไขแล้ว
2
มี.ค. 18
33912
10
ม.ค. 24
17034
Year only needed - how to implement? แก้ไขแล้ว
2
มี.ค. 15
5277