Skip to content

Commit

Permalink
[FIX] account: manual reconciliation from journal items
Browse files Browse the repository at this point in the history
  use cases fixed:
  1) go in the journal items, filter on unreconciled lines, pick just one and click on 'Action > reconcile', the manual reconciliation widget opens but you directly get the rainbowman and you can't do anything. It's not possible to reconcile the selected entry with a writeoff (to clear a customer account, for example).
  2) go in the journal items, select 2 receivable lines for the same amount but that don't have any partner set then click on 'Action > reconcile', the rainbowman directly shows without processing the reconciliation.

    To fix those issues, we now clearly bypass the regular methods in case we have active_ids and active_model == 'account.move.line', since they weren't adapted anyway.

    also implement real error message when selected lines don't have the same company or account (currently it's displaying a rainbowman): see error messages in 'reconcile()' in account_move.py

  OPW #1919727 and #1930957

  Co-authored by wan-odoo

closes odoo#29771
  • Loading branch information
qdp-odoo committed Jan 25, 2019
1 parent c8ace04 commit 19ece69
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
21 changes: 10 additions & 11 deletions addons/account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,22 +895,13 @@ def auto_reconcile_lines(self):
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:
Expand All @@ -920,6 +911,14 @@ def reconcile(self, writeoff_acc_id=False, writeoff_journal_id=False):
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()

Expand All @@ -937,7 +936,7 @@ def reconcile(self, writeoff_acc_id=False, writeoff_journal_id=False):
#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):
Expand Down
22 changes: 21 additions & 1 deletion addons/account/models/reconciliation_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,27 @@ def get_all_data_for_manual_reconciliation(self, partner_ids, account_ids):
""" 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'),
Expand Down Expand Up @@ -345,7 +366,6 @@ def get_data_for_manual_reconciliation(self, res_type, res_ids=None, account_typ
# 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
Expand Down

0 comments on commit 19ece69

Please sign in to comment.