diff --git a/account_move_transactionid_import/__manifest__.py b/account_move_transactionid_import/__manifest__.py index e4ba6bb3..59c4fca9 100644 --- a/account_move_transactionid_import/__manifest__.py +++ b/account_move_transactionid_import/__manifest__.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) { 'name': "Journal Entry transactionID import", - 'version': '12.0.1.0.0', + 'version': '12.0.2.0.0', 'author': "Camptocamp,Odoo Community Association (OCA)", 'maintainer': 'Camptocamp', 'category': 'Finance', diff --git a/account_move_transactionid_import/models/account_move.py b/account_move_transactionid_import/models/account_move.py index 858b5726..366b19a5 100644 --- a/account_move_transactionid_import/models/account_move.py +++ b/account_move_transactionid_import/models/account_move.py @@ -35,14 +35,14 @@ class AccountMoveCompletionRule(models.Model): res = {} so_obj = self.env['sale.order'] sales = so_obj.search([('transaction_id', '=', line.ref)]) - if len(sales) > 1: + partners = sales.mapped('partner_id') + if len(partners) > 1: raise ErrorTooManyPartner( _('Line named "%s" was matched by more than ' 'one partner.') % line.name) - if len(sales) == 1: - partner = sales[0].partner_id - res['partner_id'] = partner.id - res['account_id'] = partner.property_account_receivable_id.id + if len(partners) == 1: + res['partner_id'] = partners.id + res['account_id'] = partners.property_account_receivable_id.id return res def get_from_transaction_id_and_invoice(self, line): @@ -64,12 +64,19 @@ class AccountMoveCompletionRule(models.Model): invoice_obj = self.env['account.invoice'] invoices = invoice_obj.search( [('transaction_id', '=', line.ref)]) - if len(invoices) > 1: + partners = invoices.mapped('partner_id.commercial_partner_id') + accounts = invoices.mapped('account_id') + if len(partners) > 1: raise ErrorTooManyPartner( _('Line named "%s" was matched by more than ' 'one partner.') % line.name) - elif len(invoices) == 1: - invoice = invoices[0] - res['partner_id'] = invoice.commercial_partner_id.id - res['account_id'] = invoice.account_id.id + elif len(partners) == 1: + res['partner_id'] = partners.id + if len(accounts) > 1: + raise ErrorTooManyPartner( + _('Line named "%s" was matched by more than ' + 'one invoice.') % line.name + ) + elif len(accounts) == 1: + res['account_id'] = accounts.id return res