diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 09283dae105..97e48136104 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -895,22 +895,13 @@ class AccountMoveLine(models.Model): ret = self._reconcile_lines(debit_moves, credit_moves, field) return ret - @api.multi - def reconcile(self, writeoff_acc_id=False, writeoff_journal_id=False): - # Empty self can happen if the user tries to reconcile entries which are already reconciled. - # The calling method might have filtered out reconciled lines. - if not self: - return True - + def _check_reconcile_validity(self): #Perform all checks on lines company_ids = set() all_accounts = [] - partners = set() for line in self: company_ids.add(line.company_id.id) all_accounts.append(line.account_id) - if (line.account_id.internal_type in ('receivable', 'payable')): - partners.add(line.partner_id.id) if line.reconciled: raise UserError(_('You are trying to reconcile some entries that are already reconciled.')) if len(company_ids) > 1: @@ -920,6 +911,14 @@ class AccountMoveLine(models.Model): if not (all_accounts[0].reconcile or all_accounts[0].internal_type == 'liquidity'): raise UserError(_('Account %s (%s) does not allow reconciliation. First change the configuration of this account to allow it.') % (all_accounts[0].name, all_accounts[0].code)) + @api.multi + def reconcile(self, writeoff_acc_id=False, writeoff_journal_id=False): + # Empty self can happen if the user tries to reconcile entries which are already reconciled. + # The calling method might have filtered out reconciled lines. + if not self: + return True + + self._check_reconcile_validity() #reconcile everything that can be remaining_moves = self.auto_reconcile_lines() @@ -937,7 +936,7 @@ class AccountMoveLine(models.Model): #add writeoff line to reconcile algorithm and finish the reconciliation remaining_moves = (remaining_moves + writeoff_to_reconcile).auto_reconcile_lines() # Check if reconciliation is total or needs an exchange rate entry to be created - (self+writeoff_to_reconcile).check_full_reconcile() + (self + writeoff_to_reconcile).check_full_reconcile() return True def _create_writeoff(self, writeoff_vals): diff --git a/addons/account/models/reconciliation_widget.py b/addons/account/models/reconciliation_widget.py index d64a3eda85c..d4b9e616651 100644 --- a/addons/account/models/reconciliation_widget.py +++ b/addons/account/models/reconciliation_widget.py @@ -225,6 +225,27 @@ class AccountReconciliation(models.AbstractModel): """ Returns the data required for the invoices & payments matching of partners/accounts. If an argument is None, fetch all related reconciliations. Use [] to fetch nothing. """ + MoveLine = self.env['account.move.line'] + aml_ids = self._context.get('active_ids') and self._context.get('active_model') == 'account.move.line' and tuple(self._context.get('active_ids')) + if aml_ids: + aml = MoveLine.browse(aml_ids) + aml._check_reconcile_validity() + account = aml[0].account_id + currency = account.currency_id or account.company_id.currency_id + return { + 'accounts': [{ + 'reconciliation_proposition': self._prepare_move_lines(aml, target_currency=currency), + 'company_id': account.company_id.id, + 'currency_id': currency.id, + 'mode': 'accounts', + 'account_id': account.id, + 'account_name': account.name, + 'account_code': account.code, + }], + 'customers': [], + 'suppliers': [], + } + return { 'customers': self.get_data_for_manual_reconciliation('partner', partner_ids, 'receivable'), 'suppliers': self.get_data_for_manual_reconciliation('partner', partner_ids, 'payable'), @@ -345,7 +366,6 @@ class AccountReconciliation(models.AbstractModel): # be reconciled. return [r for r in rows if r['reconciliation_proposition']] + [r for r in rows if not r['reconciliation_proposition']] - @api.model def process_move_lines(self, data): """ Used to validate a batch of reconciliations in a single call