Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
2 Antworten
2840 Ansichten

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


Avatar
Verwerfen
Beste Antwort

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

Avatar
Verwerfen
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

Beste Antwort

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


Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
1
Aug. 23
29189
3
Apr. 21
8641
2
Juni 20
5814
1
Okt. 19
4753
2
Mai 17
3489