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

Hello everyone,


I created a custom field to display the status label from the quality check module to the delivery orders module. I use a computed field to display the status label.


Dependencies: check_ids.quality_state

Code:

for record in self:
    if quality_state == "none":
        record['x_studio_quality_checks'] = "To Do"
    elif quality_state == "pass":
        record['x_studio_quality_checks'] = "Passed"
    else:
        record['x_studio_quality_checks'] = "Failed"

Error:

NameError: name 'quality_state' is not defined
ValueError: : "name 'quality_state' is not defined" while evaluating
'for record in self:\r\n    if quality_state == "none":\r\n        record[\'x_studio_quality_checks\'] = "To Do"\r\n    elif quality_state == "pass":\r\n        record[\'x_studio_quality_checks\'] = "Passed"\r\n    else:\r\n        record[\'x_studio_quality_checks\'] = "Failed"'


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

Your loop is on the right track, iterating through records in self, which is good Odoo etiquette. The hiccup is that quality_state seems to be a mysterious stranger in this context. To resolve this, you'll need to determine quality_state for each record within your loop. I'm going to assume that quality_state is a field of a related quality check record (perhaps from a One2many or Many2one relationship).

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

Hi,

Ensure that you have defined the field quality_state within the function. From the dependencies you have provided, it seems that quality_state is a field in the one2many model check_ids. Therefore, you can't directly call a field name within a function without defining it first.

For example, in your code you have provided the dependency as check_ids.quality_state, so you should try to reference the field name from it. For instance:


for record in self:
    for check in record.check_ids:
        if check.quality_state == "none":

If you have multiple records in check_ids, you need to loop through them to access the quality_state field."


Hope it helps

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

Hi Christian, 

The problem is in your loop . quality_state field is in another model .
Please check the code .

for record in self.check_ids:   
if record.quality_state == "none":
        record['x_studio_quality_checks'] = "To Do"
    elif record.quality_state == "pass":
        record['x_studio_quality_checks'] = "Passed"
    else:
        record['x_studio_quality_checks'] = "Failed"


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

Hi,
See what is the value coming in quality_state variable and ensure that you are checking against the correct values ?

Are you sure that the quality_state will return Failed and not failed ? or not just fail ? Similarly for Passed, is it Passed itself, not pass or passed ?

Thanks

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

Hello Hans, thank you for your feedback. I can't comment due to low karma. Yes, quality_state is a field under Quality Checks Module. I want to display it in Delivery Orders View in Inventory Module. It works after I declare the quality_state:

for record in self:
    quality_state = str(line.quality_state for line in record.check_ids)
    if quality_state == "fail":
        record['x_studio_quality_checks'] = "Failed"
    elif quality_state == "pass":
        record['x_studio_quality_checks'] = "Passed"
    else:
        record['x_studio_quality_checks'] = "To Do"

The problem now is whenever the status in quality_state is "Passed" the value in Delivery Orders should be "Passed" but it display "To Do"

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

Hi Niyas,

Yes, I check the value in quality_state. quality_state is a selection field from Quality Check Module. Here is its selection value:
[none] - To Do
[pass] - Passed
[fail] - Failed

I want to call the value in the Delivery Orders in Inventory. I keep on tweaking the code still it display "To Do" or gets error.

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 1 25
1212
1
thg 4 24
1808
4
thg 4 24
3155
1
thg 4 24
2374
1
thg 6 23
8140