{"record":{"id":"f0597cebb533337a","repo":"odoo/odoo","slug":"please-set-a-strictly-positive-rounding-value","errorCode":null,"errorMessage":"Please set a strictly positive rounding value.","messagePattern":"Please set a strictly positive rounding value\\.","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"addons/account/models/account_cash_rounding.py","lineNumber":49,"sourceCode":"        ondelete='restrict',\n    )\n    loss_account_id = fields.Many2one(\n        'account.account',\n        string='Loss Account',\n        company_dependent=True,\n        check_company=True,\n        domain=\"[('account_type', 'not in', ('asset_receivable', 'liability_payable'))]\",\n        ondelete='restrict',\n    )\n    rounding_method = fields.Selection(string='Rounding Method', required=True,\n        selection=[('UP', 'Up'), ('DOWN', 'Down'), ('HALF-UP', 'Nearest')],\n        default='HALF-UP', help='The tie-breaking rule used for float rounding operations')\n\n    @api.constrains('rounding')\n    def validate_rounding(self):\n        for record in self:\n            if record.rounding <= 0:\n                raise ValidationError(_(\"Please set a strictly positive rounding value.\"))\n\n    def round(self, amount):\n        \"\"\"Compute the rounding on the amount passed as parameter.\n\n        :param amount: the amount to round\n        :return: the rounded amount depending the rounding value and the rounding method\n        \"\"\"\n        return float_round(amount, precision_rounding=self.rounding, rounding_method=self.rounding_method)\n\n    def compute_difference(self, currency, amount):\n        \"\"\"Compute the difference between the base_amount and the amount after rounding.\n        For example, base_amount=23.91, after rounding=24.00, the result will be 0.09.\n\n        :param currency: The currency.\n        :param amount: The amount\n        :return: round(difference)\n        \"\"\"\n        amount = currency.round(amount)","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/odoo/odoo/blob/1e661df964b1b264c9cef3ab28430d4785be3fda/addons/account/models/account_cash_rounding.py#L31-L67","documentation":"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.","triggerScenarios":"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'}).","commonSituations":"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.","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."],"exampleFix":"# before\nenv['account.cash.rounding'].create({\n    'name': ' Nickel rounding', 'rounding': 0.0, 'rounding_method': 'HALF-UP'})\n# -> ValidationError\n\n# after\nenv['account.cash.rounding'].create({\n    'name': 'Nickel rounding', 'rounding': 0.05, 'rounding_method': 'HALF-UP'})","handlingStrategy":"validation","validationCode":"if not isinstance(rounding_value, (int, float)) or rounding_value <= 0:\n    raise ValueError('cash rounding precision must be > 0')","typeGuard":null,"tryCatchPattern":"from odoo.exceptions import ValidationError\ntry:\n    env['account.cash.rounding'].create(vals)\nexcept ValidationError as e:\n    if 'strictly positive' in str(e):\n        vals['rounding'] = 0.05  # sensible default, then retry\n        env['account.cash.rounding'].create(vals)\n    else:\n        raise","preventionTips":["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."],"tags":["odoo","accounting","cash-rounding","constraint","validation"],"backgroundTag":null,"analyzedSha":"1e661df964b1b264c9cef3ab28430d4785be3fda","analyzedAt":"2026-08-15T05:22:16.142Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}