I added a constraint on standard_price in my custom module to prevent zero or negative values:
@api.constrains('standard_price') def _check_standard_price(self): price_unit_prec = self.env['decimal.precision'].precision_get('Product Price') for rec in self: if float_compare(rec.standard_price, 0.0, precision_rounding=price_unit_prec) < 1: print("_check_standard_price", rec.standard_price) raise ValidationError(_('Invalid Cost Price.'))
Problem:
Entering 1 triggers a ValidationError, even though it’s positive. My debug prints show:
float_compare rounding_factor 3 value1 0.0 value2 0.0 delta 0.0 float_is_zero epsilon 3 _check_standard_price 1.0
Analysis:
- price_unit_prec comes from Decimal Accuracy → Product Price (3 in my case).
- Odoo rounds using float_round(value, rounding_factor), so 1 gets rounded to 0.0 and fails the check.
- Changing Decimal Accuracy to 2 makes it work correctly (1 → 1.00).