[FIX] account: manual reconciliation from journal items
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/odoo#29771
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user