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
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Księgowość
- Zapasy
- PoS
- Project
- MRP
To pytanie dostało ostrzeżenie
1
Odpowiedz
4979
Widoki
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.
Podoba Ci się ta dyskusja? Dołącz do niej!
Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!
Zarejestruj sięPowiązane posty | Odpowiedzi | Widoki | Czynność | |
---|---|---|---|---|
|
2
gru 19
|
7775 | ||
|
2
lip 24
|
5693 | ||
|
1
lis 22
|
7303 | ||
|
2
lip 22
|
8210 | ||
|
2
sie 24
|
9755 |