Skip to Content
Menu
This question has been flagged
5 Replies
2346 Views

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"'


Avatar
Discard
Best Answer

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).

Avatar
Discard
Best Answer

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

Avatar
Discard
Best Answer

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"


Avatar
Discard
Best Answer

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

Avatar
Discard
Author Best Answer

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"

Avatar
Discard
Author

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.

Related Posts Replies Views Activity
0
Jan 25
770
1
Apr 24
1220
4
Apr 24
2419
1
Apr 24
1743
1
Jun 23
7266