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

I am using button to change my custom model states, I want to required a field on specific state, below is my field defined in xml.



When state is in progress the field is got require but when I click on next stage it goes to next why it doesn't popup's the danger notification, that field is required.

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

Hello Maqsood Ahmad,

Since 17.0, the "attrs" and "states" attributes are no longer used Therefore,

To make a field required in a specific view, you can use the following syntax:
// Syntax is added in comments

I Hope this information proves helpful to you.

Thanks & Regards,

Email:   odoo@aktivsoftware.com           

Skype: kalpeshmaheshwari 

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

Syntax:
<field name="your_field_name" required="state in ['your_state']"/>

Câu trả lời hay nhất

Hi,

Add required attribute on your field.

Example:

<field name="your_field_name" required="state in ['progress']"/>

But this will effect only on UI level.

For validation, you must enforce server-side validation in Python.

Use either a method override (e.g., button logic) or @api.constrains.

  @api.constrains('state', 'your_field')
    def _check_required_field_on_in_progress(self):
        for rec in self:
            if rec.state == 'progress' and not rec.your_field:
                raise ValidationError(_("The field 'Your Field' is required in 'In Progress' state."))
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 9 24
2704
1
thg 8 24
1408
0
thg 8 24
1644
1
thg 6 24
1614
4
thg 6 25
2371