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

Hi. I've created two custom fields in my sale.order model:

  1. Order Prirority: Field Name: x_order_prirority, Field Type: selection, selection_ids (1 for '!', 2 for '!!', 3 for '!!!')

  2. Rush: Field Name: x_rush, Field Type: boolean.

What I want to do is this: I placed these two fields on the sales order form, and when the priority is selected as "!!!", I want the Rush field would be checked

I wrote these lines of codes in x_rush field compute area, and it gave me syntax error. I'm new to Python language. 

Dependencies: x_order_prirority

Compute: for record in self:
  if record ['x_order_prirority'] = 3 :
    self = true

Any help? Thanks. 


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

Thanks @Hilar for you answer, I tried to comment you answer directly, but I don't have enough Karma. (By the way, this Karma thing is bullshit!)

Your answer gave me some light on this matter, though I'm having the same syntax error.

I also tried this: 

Since the x_order_prirority is a selection, so I wrote the code like this: 

for record in self: 
    if record.x_order_prirority.selection_ids.value = '3' :  // selection_ids.value is actually a 'char' type, not an integer
        record.x_rush = True

But again, syntax error.

Any help? Thanks.

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

self will be the current model object. you must assign values as

self.field_name = x or self['field_name'] = x

In your case it must be

for record in self:
  if record ['x_order_prirority'] = 3 :
    record.x_rush = True
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 6 25
15389
3
thg 4 25
5563
Compute Fields Đã xử lý
2
thg 7 24
2626
1
thg 1 24
1835
1
thg 7 22
2245