From a7ee151f152881ab053f91ae26efe96e36377554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Valyi?= Date: Mon, 5 Dec 2022 20:01:24 -0300 Subject: [PATCH] [REF] try/except in _compute_matching_number --- account_usability/models/account_move.py | 29 ++++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/account_usability/models/account_move.py b/account_usability/models/account_move.py index e32f18c..d4f700b 100644 --- a/account_usability/models/account_move.py +++ b/account_usability/models/account_move.py @@ -2,13 +2,15 @@ # @author Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from datetime import timedelta import logging +from psycopg2 import IntegrityError + from odoo import api, fields, models, _ +from odoo.exceptions import UserError +from odoo.osv import expression 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 _logger = logging.getLogger(__name__) @@ -220,7 +222,7 @@ class AccountMove(models.Model): if self.is_purchase_document(include_receipts=True): tax_lock_date = self.company_id.tax_lock_date if invoice_date and tax_lock_date and has_tax and invoice_date <= tax_lock_date: - invoice_date = tax_lock_date + timedelta(days=1) + invoice_date = tax_lock_date + timedelta(days=1) date = invoice_date return date @@ -264,13 +266,20 @@ class AccountMoveLine(models.Model): def _compute_matching_number(self): # TODO maybe it will be better to have the same maching_number for # all partial so it will be easier to group by - super()._compute_matching_number() for record in self: - if record.matching_number == "P": - record.matching_number = ", ".join([ - "a%d" % pr.id - for pr in record.matched_debit_ids + record.matched_credit_ids - ]) + try: + super(AccountMoveLine, record)._compute_matching_number() + if record.matching_number == "P": + record.matching_number = ", ".join([ + "a%d" % pr.id + for pr in record.matched_debit_ids + record.matched_credit_ids + ]) + except IntegrityError as error: + _logger.info( + f"unable to update matching number for line ID {record.id}," + "{record.display_name}" + ) + _logger.info(error) def _get_computed_name(self): # This is useful when you want to have the product code in a dedicated