odoo/odoo · error · ValidationError
Please set a strictly positive rounding value.
Error message
Please set a strictly positive rounding value.
What it means
Raised by the @api.constrains('rounding') validate_rounding on account.cash.rounding. The rounding field is the precision unit used by float_round, so it must be strictly greater than zero; zero or negative values would make rounding degenerate (or divide by zero in consumers) and are rejected.
Source
Thrown at addons/account/models/account_cash_rounding.py:49
ondelete='restrict',
)
loss_account_id = fields.Many2one(
'account.account',
string='Loss Account',
company_dependent=True,
check_company=True,
domain="[('account_type', 'not in', ('asset_receivable', 'liability_payable'))]",
ondelete='restrict',
)
rounding_method = fields.Selection(string='Rounding Method', required=True,
selection=[('UP', 'Up'), ('DOWN', 'Down'), ('HALF-UP', 'Nearest')],
default='HALF-UP', help='The tie-breaking rule used for float rounding operations')
@api.constrains('rounding')
def validate_rounding(self):
for record in self:
if record.rounding <= 0:
raise ValidationError(_("Please set a strictly positive rounding value."))
def round(self, amount):
"""Compute the rounding on the amount passed as parameter.
:param amount: the amount to round
:return: the rounded amount depending the rounding value and the rounding method
"""
return float_round(amount, precision_rounding=self.rounding, rounding_method=self.rounding_method)
def compute_difference(self, currency, amount):
"""Compute the difference between the base_amount and the amount after rounding.
For example, base_amount=23.91, after rounding=24.00, the result will be 0.09.
:param currency: The currency.
:param amount: The amount
:return: round(difference)
"""
amount = currency.round(amount)View on GitHub (pinned to 1e661df964)
Solutions
- Set a positive precision such as 0.05, 0.10, or 1.0 depending on the cash rounding rule you need.
- Fix the import/source data to always supply a positive rounding value.
- Guard in code: only create the rounding record when the parsed value > 0.
Example fix
# before
env['account.cash.rounding'].create({
'name': ' Nickel rounding', 'rounding': 0.0, 'rounding_method': 'HALF-UP'})
# -> ValidationError
# after
env['account.cash.rounding'].create({
'name': 'Nickel rounding', 'rounding': 0.05, 'rounding_method': 'HALF-UP'}) Defensive patterns
Strategy: validation
Validate before calling
if not isinstance(rounding_value, (int, float)) or rounding_value <= 0:
raise ValueError('cash rounding precision must be > 0') Try / catch
from odoo.exceptions import ValidationError
try:
env['account.cash.rounding'].create(vals)
except ValidationError as e:
if 'strictly positive' in str(e):
vals['rounding'] = 0.05 # sensible default, then retry
env['account.cash.rounding'].create(vals)
else:
raise Prevention
- Always supply a positive rounding value (e.g. 0.05/0.10/1.0) in cash rounding configs.
- Validate parsed import values for rounding before creating records.
- Guard form/test data: reject zero or negative precision early in your own layer.
When it happens
Trigger: Creating or writing an account.cash.rounding record with rounding <= 0 (0.0 or a negative number), e.g. create({'rounding': 0.0, 'rounding_method': 'HALF-UP'}).
Common situations: Importing rounding configurations where the precision column is empty and parsed as 0; UI form saved before filling the rounding value (rare, field defaults may be 0); tests creating placeholder rounding records.
Related errors
- Account Groups with the same granularity can't overlap
- The journal item is not linked to the correct financial acco
- Only a report without a root report of its own can be select
- Incorrect fiscal year date: day is out of range for month. M
- At least one analytic account must be set
AI-assisted analysis of odoo/odoo@1e661df964 (2026-08-15).
Data as JSON: /api/errors/f0597cebb533337a.
Report an issue: GitHub.