Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
5086 Weergaven

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

Avatar
Annuleer
Beste antwoord

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.


Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
2
dec. 19
7906
2
jul. 24
5793
1
nov. 22
7511
2
jul. 22
8422
2
aug. 24
9877