[REF] try/except in _compute_matching_number

This commit is contained in:
Raphaël Valyi
2022-12-05 20:01:24 -03:00
parent 819d145763
commit a7ee151f15

View File

@@ -2,13 +2,15 @@
# @author Alexis de Lattre <alexis.delattre@akretion.com> # @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from datetime import timedelta
import logging import logging
from psycopg2 import IntegrityError
from odoo import api, fields, models, _ 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 import float_is_zero
from odoo.tools.misc import format_date 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__) _logger = logging.getLogger(__name__)
@@ -264,13 +266,20 @@ class AccountMoveLine(models.Model):
def _compute_matching_number(self): def _compute_matching_number(self):
# TODO maybe it will be better to have the same maching_number for # TODO maybe it will be better to have the same maching_number for
# all partial so it will be easier to group by # all partial so it will be easier to group by
super()._compute_matching_number()
for record in self: for record in self:
try:
super(AccountMoveLine, record)._compute_matching_number()
if record.matching_number == "P": if record.matching_number == "P":
record.matching_number = ", ".join([ record.matching_number = ", ".join([
"a%d" % pr.id "a%d" % pr.id
for pr in record.matched_debit_ids + record.matched_credit_ids 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): def _get_computed_name(self):
# This is useful when you want to have the product code in a dedicated # This is useful when you want to have the product code in a dedicated