Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
2851 Vizualizări

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


Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
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

Cel mai bun răspuns

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.")


Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
aug. 23
29189
3
apr. 21
8645
2
iun. 20
5814
1
oct. 19
4753
2
mai 17
3489