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

Hello Everyone,

Is it possible to display multiple status in List View? I want to display the status from quality check to the delivery orders. For example, there are 2 products in one PO and each products undergo quality check before delivering. If one product is Pass it displays Passed in the List View similarly if the product is Failed. I can only display one status label using related field. How can I do it in computed field, I do mine but it runs in error:


Dependencies:

check_ids, check_ids.quality_state

Code:

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

Error:

KeyError: 'x_studio_quality_checks'
ValueError: : "x_studio_quality_checks" while evaluating



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

Hi Christian Lloyd,

Yes, it's possible to display multiple statuses in a list view in Odoo using a computed field. you can try it in this way:

        for record in self:
            if record.check_ids:
                # Assuming check_ids is a One2many field containing quality checks
                # Iterate over quality checks and set the status based on quality_state
                passed = all(check.quality_state == 'pass' for check in record.check_ids)
                failed = any(check.quality_state == 'fail' for check in record.check_ids)
                if failed:
                    record.x_studio_quality_checks = 'Failed'
                elif passed:
                    record.x_studio_quality_checks = 'Passed'
                else:
                    record.x_studio_quality_checks = 'To Do'
            else:
                record.x_studio_quality_checks = 'To Do'

In this code:

  • check_ids is assumed to be a One2many field containing quality checks related to your model.
  • We iterate over each record and check the quality_state of each related quality check.
  • If all quality checks pass, the status is set to 'Passed'. If any quality check fails, the status is set to 'Failed'. Otherwise, it's set to 'To Do'.
  • The computed field x_studio_quality_checks is updated for each record accordingly.


Hope it helps

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

Hi Christian Lloyd,

Can you try this way,


Ảnh đại diện
Huỷ bỏ