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

In an expense record, the unit amount value must never be 0.00. Hence,  I want an error to be raised when the unit amount is 0.00

I added the below code:

    @api.onchange('unit_amount')
    def write(self):
        if self.unit_amount == 0.00:
            raise UserError(_('You are not allowed to create expenses with 0 value'))

The above user error is raised as soon as the Create button is clicked because, unit amount value is by default set as as 0.00

Please provide an alternate suggestion

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

you can use api.constrains

see below code.

@api.constrains('unit_amount')
def check_unit_amount(self):
    if self.unit_amount <= 0:
        raise UserError("You are not allowed to create expenses with 0 value")


Thanks.


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 12 19
7788
2
thg 7 24
5703
1
thg 11 22
7310
2
thg 7 22
8224
2
thg 8 24
9761