Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
2311 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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


Ảnh đại diện
Huỷ bỏ
Tác giả

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

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 1 24
1156
3
thg 9 23
2160
2
thg 3 18
33912
10
thg 1 24
17033
2
thg 3 15
5277