From a498497962612d8091d49c33f00172bebb3327bc Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Fri, 30 Oct 2020 14:19:26 +0000 Subject: [PATCH] [IMP] account: Allow skipping statement line on payments A classic payment uses the outstanding account to create the line that needs to be matched later with a statement line. In some cases, the user doesn't want to encode twice the same transaction, e.g. when encoding a cash payment, and want to create directly a payment impacting the cash account to skip the 'statement line' step. X-original-commit: 2b472fd59e8eebbc2cf1f592cf6e657f2ae9e778 --- addons/account/models/account_journal.py | 11 ++++++++--- addons/account/models/account_payment.py | 9 +++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/addons/account/models/account_journal.py b/addons/account/models/account_journal.py index bb3671608fb..5dadddadbcf 100644 --- a/addons/account/models/account_journal.py +++ b/addons/account/models/account_journal.py @@ -87,7 +87,7 @@ class AccountJournal(models.Model): "receivable account.", string='Outstanding Receipts Account', domain=lambda self: "[('deprecated', '=', False), ('company_id', '=', company_id), \ ('user_type_id.type', 'not in', ('receivable', 'payable')), \ - ('user_type_id', '=', %s)]" % self.env.ref('account.data_account_type_current_assets').id) + '|', ('user_type_id', '=', %s), ('id', '=', default_account_id)]" % self.env.ref('account.data_account_type_current_assets').id) payment_credit_account_id = fields.Many2one( comodel_name='account.account', check_company=True, copy=False, ondelete='restrict', help="Outgoing payments entries triggered by bills/credit notes will be posted on the Outstanding Payments Account " @@ -96,7 +96,7 @@ class AccountJournal(models.Model): "payable account.", string='Outstanding Payments Account', domain=lambda self: "[('deprecated', '=', False), ('company_id', '=', company_id), \ ('user_type_id.type', 'not in', ('receivable', 'payable')), \ - ('user_type_id', '=', %s)]" % self.env.ref('account.data_account_type_current_assets').id) + '|', ('user_type_id', '=', %s), ('id', '=', default_account_id)]" % self.env.ref('account.data_account_type_current_assets').id) suspense_account_id = fields.Many2one( comodel_name='account.account', check_company=True, ondelete='restrict', readonly=False, store=True, compute='_compute_suspense_account_id', @@ -761,7 +761,12 @@ class AccountJournal(models.Model): accounts = self.payment_debit_account_id + self.payment_credit_account_id if not accounts: - return 0.0 + return 0.0, 0 + + # Allow user managing payments without any statement lines. + # In that case, the user manages transactions only using the register payment wizard. + if self.default_account_id in accounts: + return 0.0, 0 domain = (domain or []) + [ ('account_id', 'in', tuple(accounts.ids)), diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index 9bf7a5aa02a..8a26d5d8eec 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -285,11 +285,16 @@ class AccountPayment(models.Model): pay.is_reconciled = True pay.is_matched = True else: - # The journal entry seems reconciled. residual_field = 'amount_residual' if pay.currency_id == pay.company_id.currency_id else 'amount_residual_currency' + if pay.journal_id.default_account_id and pay.journal_id.default_account_id in liquidity_lines.account_id: + # Allow user managing payments without any statement lines by using the bank account directly. + # In that case, the user manages transactions only using the register payment wizard. + pay.is_matched = True + else: + pay.is_matched = pay.currency_id.is_zero(sum(liquidity_lines.mapped(residual_field))) + reconcile_lines = (counterpart_lines + writeoff_lines).filtered(lambda line: line.account_id.reconcile) pay.is_reconciled = pay.currency_id.is_zero(sum(reconcile_lines.mapped(residual_field))) - pay.is_matched = pay.currency_id.is_zero(sum(liquidity_lines.mapped(residual_field))) @api.model def _get_method_codes_using_bank_account(self):