<commit_before># -*- coding: utf-8 -*-
# Copyright 2021 <NAME>/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class AccountCagnotte(models.Model):

    _inherit = "account.cagnotte"

    no_negative = fields.Boolean(
        track_visibility="onchange",
        default=lambda self: self.cagnotte_type_id.no_negative,
    )
    is_negative = fields.Boolean(
        compute="_compute_is_negative",
        store=True,
    )

    @api.multi
    @api.onchange("cagnotte_type_id")
    def _onchange_cagnotte_type_id(self):
        for cagnotte in self:
            if not cagnotte.no_negative:
                cagnotte.no_negative = cagnotte.cagnotte_type_id.no_negative

    @api.multi
    @api.constrains("solde_cagnotte", "no_negative")
    def _check_no_negative(self):
        for cagnotte in self.filtered("no_negative"):
            if cagnotte.solde_cagnotte < 0:
                raise ValidationError(
                    _("The cagnotte balance cannot be negative !"))<commit_msg>[10.0][IMP] cagnotte_no_negative: Compare with precision<commit_after># -*- coding: utf-8 -*-
# Copyright 2021 <NAME>/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.tools.float_utils import float_compare
from odoo.exceptions import ValidationError


class AccountCagnotte(models.Model):

    _inherit = "account.cagnotte"

    no_negative = fields.Boolean(
        track_visibility="onchange",
        default=lambda self: self.cagnotte_type_id.no_negative,
    )
    is_negative = fields.Boolean(
        compute="_compute_is_negative",
        store=True,
    )

    @api.multi
    @api.onchange("cagnotte_type_id")
    def _onchange_cagnotte_type_id(self):
        for cagnotte in self:
            if not cagnotte.no_negative:
                cagnotte.no_negative = cagnotte.cagnotte_type_id.no_negative

    @api.multi
    @api.constrains("solde_cagnotte", "no_negative")
    def _check_no_negative(self):
        for cagnotte in self.filtered("no_negative"):
            rounding = cagnotte.company_currency_id.rounding
            compare = float_compare(
                cagnotte.solde_cagnotte, 0, precision_rounding=rounding)
            if compare < 0:
                raise ValidationError(
                    _("The cagnotte balance cannot be negative !"))
{'fraction_non_alphanumeric': 0.09897330595482547, 'fraction_numerical': 0.008213552361396304, 'mean_word_length': 2.8241758241758244, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5992967', 'n_tokens_mistral': 830, 'n_tokens_neox': 790, 'n_words': 153}