From c12b4960048025fe931dada847a9af7dce5f8cad Mon Sep 17 00:00:00 2001 From: clementmbr Date: Wed, 26 Jan 2022 09:08:18 -0300 Subject: [PATCH] account_usability: explicit error msg on unposted reconciliation --- account_usability/models/account_move.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/account_usability/models/account_move.py b/account_usability/models/account_move.py index 035a8b1..6b956e0 100644 --- a/account_usability/models/account_move.py +++ b/account_usability/models/account_move.py @@ -2,11 +2,12 @@ # @author Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, fields, models +from odoo import api, fields, models, _ from odoo.tools import float_is_zero from odoo.tools.misc import format_date from odoo.osv import expression from datetime import timedelta +from odoo.exceptions import UserError class AccountMove(models.Model): @@ -276,3 +277,14 @@ class AccountMoveLine(models.Model): if no_product_code_param and no_product_code_param == 'True': self = self.with_context(display_default_code=False) return super()._get_computed_name() + + def reconcile(self): + """Explicit error message if unposted lines""" + unposted_ids = self.filtered(lambda l: l.move_id.state != "posted") + if unposted_ids: + m = _("Please post the following entries before reconciliation :") + sep = "\n - " + unpost = sep.join([am.display_name for am in unposted_ids.move_id]) + raise UserError(m + sep + unpost) + + return super().reconcile()