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

Hello,


I created with studio and new field in contact. This is for the french department. 

I would like to create an automatic action to use the 2 first digit of the zip code and use it as the department. 


I start to study Python and try to create this code.  

postal_code_1= str(zip)
departement =  postal_code_1 [0:2]
x_studio_departement =  departement


I received an error coming from the last line of the code. Have you a proposition to adapt the code ?


Thanks a lot for your help,

Julien

 

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

Hi,
To write value into the record either you can use the write method or you can update like a dict.

Most probably you may be using the . operation to assign the value and thus getting the error. In the automated action or in the server action, you cannot assign value using the . operator.

record.field_name = value this method is wrong

Instead:
record.write({'field_name': value})   or record['field_name'] = value

Thanks

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

Hi,

Try this code :

      for record in self:

           if record['zip']:
               postal_code = str(record['zip'])
               department = postal_code[0:2] 
                record['x_studio_department'] = department


Hope it helps

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
Open a URL Đã xử lý
2
thg 10 22
7002
1
thg 2 25
1269
1
thg 12 24
2638
0
thg 11 23
1256
1
thg 11 22
3735