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

I am not a programmer and i use studio and automations to customize my database. This question concerns an automation that i want to input text to a field. 

If a field in sales order line is empty a short text is inserted to the field. I have everything set except the correct python expression. Anyone have an idea what syntax to achieve this?


Thanks!


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

Thanks MML,


i had to go with a different solution this time since i didn´t have acces to the default field in the sales order line. 


Peter

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

You can use the following python expression in the "Default Value" field of the field in the sales order line to insert a short text if the field is empty:

if not self.field_name:
self.field_name = 'Short Text'

Here, field_name is the name of the field you want to set the default value for. You can replace 'Short Text' with the desired text. This expression will check if the field is empty (i.e. its value is False), and if so, set its value to the specified text.

You can use this expression in the default_get method of the sales order line model to set the default value for the field when a new sales order line is created. For example:

ef default_get(self, fields):
res = super(SaleOrderLine, self).default_get(fields)
if 'field_name' in fields:
if not res.get('field_name'):
res['field_name'] = 'Short Text'
return res

Here, SaleOrderLine is the name of your sales order line model.

MML

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 1 22
5083
1
thg 2 25
1251
1
thg 1 23
2848
0
thg 6 22
1998
1
thg 5 22
4464