[REM] account: Remove on-the-fly payments when reconciling the statement line

This option is there because it was needed by the Mexican EDI to send payments to the government.
Since the refactoring made at revision:
https://github.com/odoo/enterprise/commit/1ccb480b8e95f5702b6fb4e01446d24107514550
... this feature is no longer needed.

closes odoo/odoo#68020

Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
Laurent Smet
2021-03-17 13:43:15 +00:00
parent 8992955db2
commit 3e1d81429b
2 changed files with 3 additions and 201 deletions
@@ -1012,14 +1012,12 @@ class AccountBankStatementLine(models.Model):
# RECONCILIATION METHODS
# -------------------------------------------------------------------------
def _prepare_reconciliation(self, lines_vals_list, create_payment_for_invoice=False):
def _prepare_reconciliation(self, lines_vals_list):
''' Helper for the "reconcile" method used to get a full preview of the reconciliation result. This method is
quite useful to deal with reconcile models or the reconciliation widget because it ensures the values seen by
the user are exactly the values you get after reconciling.
:param lines_vals_list: See the 'reconcile' method.
:param create_payment_for_invoice: A flag indicating the statement line must create payments on the fly during
the reconciliation.
:return: The diff to be applied on the statement line as a tuple
(
lines_to_create: The values to create the account.move.line on the statement line.
@@ -1085,58 +1083,10 @@ class AccountBankStatementLine(models.Model):
balance = line_vals['debit'] - line_vals['credit']
amount_currency = line_vals['amount_currency']
reconciliation_vals = {
reconciliation_overview.append({
'line_vals': line_vals,
'counterpart_line': line,
}
if create_payment_for_invoice and line.account_internal_type in ('receivable', 'payable'):
# Prepare values to create a new account.payment.
payment_vals = self.env['account.payment.register']\
.with_context(active_model='account.move.line', active_ids=line.ids)\
.create({
'amount': abs(amount_currency) if line_vals['currency_id'] else abs(balance),
'payment_date': self.date,
'payment_type': 'inbound' if balance < 0.0 else 'outbound',
'journal_id': self.journal_id.id,
'currency_id': (self.foreign_currency_id or self.currency_id).id,
})\
._create_payment_vals_from_wizard()
if payment_vals['payment_type'] == 'inbound':
liquidity_account = self.journal_id.payment_debit_account_id
else:
liquidity_account = self.journal_id.payment_credit_account_id
# Preserve the rate of the statement line.
payment_vals['line_ids'] = [
# Receivable / Payable line.
(0, 0, {
**line_vals,
}),
# Liquidity line.
(0, 0, {
**line_vals,
'amount_currency': -line_vals['amount_currency'],
'debit': line_vals['credit'],
'credit': line_vals['debit'],
'account_id': liquidity_account.id,
}),
]
# Prepare the line to be reconciled with the payment.
if payment_vals['payment_type'] == 'inbound':
# Receive money.
line_vals['account_id'] = self.journal_id.payment_debit_account_id.id
elif payment_vals['payment_type'] == 'outbound':
# Send money.
line_vals['account_id'] = self.journal_id.payment_credit_account_id.id
reconciliation_vals['payment_vals'] = payment_vals
reconciliation_overview.append(reconciliation_vals)
})
total_balance += balance
total_amount_currency += amount_currency
@@ -1219,26 +1169,6 @@ class AccountBankStatementLine(models.Model):
raise UserError(_("Unable to create an open balance for a statement line because the receivable "
"/ payable accounts are missing on the partner."))
# ==== Create & reconcile payments ====
# When reconciling to a receivable/payable account, create an payment on the fly.
pay_reconciliation_overview = [reconciliation_vals
for reconciliation_vals in reconciliation_overview
if reconciliation_vals.get('payment_vals')]
if pay_reconciliation_overview:
payment_vals_list = [reconciliation_vals['payment_vals'] for reconciliation_vals in pay_reconciliation_overview]
payments = self.env['account.payment'].create(payment_vals_list)
payments.action_post()
for reconciliation_vals, payment in zip(pay_reconciliation_overview, payments):
reconciliation_vals['payment'] = payment
# Reconcile the newly created payment with the counterpart line.
(reconciliation_vals['counterpart_line'] + payment.line_ids)\
.filtered(lambda line: line.account_id == reconciliation_vals['counterpart_line'].account_id)\
.reconcile()
# ==== Create & reconcile lines on the bank statement line ====
to_create_commands = [(0, 0, open_balance_vals)] if open_balance_vals else []
@@ -1358,134 +1358,6 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon):
{'name': 'whatever', 'account_id': random_acc_1.id, 'balance': -100.0},
])
def test_reconciliation_statement_line_with_generated_payments(self):
self.statement.button_post()
receivable_account = self.company_data['default_account_receivable']
payment_account = self.bank_journal_1.payment_debit_account_id
random_account = self.company_data['default_account_revenue']
test_move = self.env['account.move'].create({
'move_type': 'entry',
'date': fields.Date.from_string('2016-01-01'),
'line_ids': [
(0, None, {
'name': 'counterpart of the whole move',
'account_id': random_account.id,
'debit': 0.0,
'credit': 1000.0,
}),
(0, None, {
'name': 'test line 1',
'account_id': receivable_account.id,
'debit': 100.0,
'credit': 0.0,
}),
(0, None, {
'name': 'test line 2',
'account_id': receivable_account.id,
'currency_id': self.currency_2.id,
'debit': 900.0,
'credit': 0.0,
'amount_currency': 1500.0,
}),
]
})
test_move.action_post()
test_line_1 = test_move.line_ids.filtered(lambda line: line.name == 'test line 1')
test_line_2 = test_move.line_ids.filtered(lambda line: line.name == 'test line 2')
statement_line = self.statement_line
StatementLine_prepare_reconciliation = type(statement_line)._prepare_reconciliation
def _prepare_reconciliation(self, lines_vals_list, create_payment_for_invoice=False):
if self == statement_line:
create_payment_for_invoice = True
return StatementLine_prepare_reconciliation(self, lines_vals_list, create_payment_for_invoice)
with patch.object(type(statement_line), '_prepare_reconciliation', _prepare_reconciliation):
self.statement_line.reconcile([
{'id': test_line_1.id, 'balance': -50.0},
{'id': test_line_2.id},
])
self.assertBankStatementLine(self.statement_line, {
**self.expected_st_line,
'is_reconciled': True,
}, [
{
'name': 'test line 2',
'account_id': payment_account.id,
'currency_id': self.currency_2.id,
'debit': 0.0,
'credit': 750.0,
'amount_currency': -1500.0,
},
{
'name': 'line_1: Open Balance',
'account_id': receivable_account.id,
'currency_id': self.currency_2.id,
'debit': 0.0,
'credit': 450.0,
'amount_currency': -900.0,
},
{
'name': 'test line 1',
'account_id': payment_account.id,
'currency_id': self.currency_2.id,
'debit': 0.0,
'credit': 50.0,
'amount_currency': -100.0,
},
self.expected_bank_line,
])
# Check generated payments.
self.assertRecordValues(test_line_1.matched_credit_ids.credit_move_id.payment_id.line_ids.sorted('balance'), [
{
'partner_id': self.statement_line.partner_id.id,
'currency_id': self.currency_2.id,
'account_id': test_line_1.account_id.id,
'debit': 0.0,
'credit': 50.0,
'amount_currency': -100.0,
'amount_residual': 0.0,
'amount_residual_currency': 50.0,
},
{
'partner_id': self.statement_line.partner_id.id,
'currency_id': self.currency_2.id,
'account_id': payment_account.id,
'debit': 50.0,
'credit': 0.0,
'amount_currency': 100.0,
'amount_residual': 0.0,
'amount_residual_currency': 0.0,
},
])
self.assertRecordValues(test_line_2.matched_credit_ids.credit_move_id.payment_id.line_ids.sorted('balance'), [
{
'partner_id': self.statement_line.partner_id.id,
'currency_id': self.currency_2.id,
'account_id': test_line_2.account_id.id,
'debit': 0.0,
'credit': 750.0,
'amount_currency': -1500.0,
'amount_residual': 0.0,
'amount_residual_currency': 0.0,
},
{
'partner_id': self.statement_line.partner_id.id,
'currency_id': self.currency_2.id,
'account_id': payment_account.id,
'debit': 750.0,
'credit': 0.0,
'amount_currency': 1500.0,
'amount_residual': 0.0,
'amount_residual_currency': 0.0,
},
])
def test_conversion_rate_rounding_issue(self):
''' Ensure the reconciliation is well handling the rounding issue due to multiple currency conversion rates.