Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
2856 Widoki

need help about minimum input value in field odoo

code below

xml version="1.0"?><xpathexpr="//field[@name='order_line']/tree//field[@name='price_unit']"position="after">
​<fieldname="purchase_price"groups="base.group_user"required="1" min="1"/>
xpath>

but still not work, user can save default value 0.00 of purchase_pirce


Awatar
Odrzuć
Najlepsza odpowiedź

Hi Wimpy,

Write a constraint for the purchase price that prevents records with a purchase value less than or equal to zero.

@api.constrains('purchase_price')
def _check_purchase_price(self):
for record in self:
if record.purchase_price <= 0:
raise ValidationError("Purchase price must be greater than 0.")


Hope it helps,
Kiran K

Awatar
Odrzuć
Autor

Kiran,
need to write models? or can be written on view xml

Thanks for answer

In models, it will work when you save the purchase order record. You can achieve this using the onchange method if you want to throw the warning before creating the new line.

Autor

ok, i will try this method.

Thanks fo answer

Najlepsza odpowiedź

Hi,

In this case you have an option to set the value of the field default as 1


example:


from odoo import models, fields


class YourModel(models.Model):

    _inherit = 'your.model'


    your_float_field = fields.Float(string='Your Float Field', default=1.0)



OR


You can add a validation to it


from odoo import models, fields, api

from odoo.exceptions import ValidationError


class YourModel(models.Model):

    _inherit = 'your.model'


    your_float_field = fields.Float(string='Your Float Field')


    @api.constrains('your_float_field')

    def _check_minimum_value(self):

        for record in self:

            if record.your_float_field

                raise ValidationError("The value of 'Your Float Field' must be at least 1.")


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
sie 23
29190
3
kwi 21
8648
2
cze 20
5816
1
paź 19
4755
2
maj 17
3490