From 5ea27d471e3c4458361b2fc9862e9a4474b1278b Mon Sep 17 00:00:00 2001
From: Jaykishan Solanki <jao@odoo.com>
Date: Wed, 18 Apr 2018 13:32:59 +0200
Subject: [PATCH] [IMP] account: Accounting Date on bank statement

This commits adds a field on bank statement that will be used to force the creation of the accounting entries at this date instead of the bank statement date (in the same way than on invoices). This is useful if the accounting period in which the entries should normally be booked is already closed.
This field is only visible in debug mode.

Was PR #22441
Was task 46892
---
 addons/account/models/account_bank_statement.py | 4 +++-
 addons/account/views/account_view.xml           | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py
index 4dff3dc3f6ce..419c056f2236 100644
--- a/addons/account/models/account_bank_statement.py
+++ b/addons/account/models/account_bank_statement.py
@@ -138,6 +138,8 @@ class AccountBankStatement(models.Model):
     date_done = fields.Datetime(string="Closed On")
     balance_start = fields.Monetary(string='Starting Balance', states={'confirm': [('readonly', True)]}, default=_default_opening_balance)
     balance_end_real = fields.Monetary('Ending Balance', states={'confirm': [('readonly', True)]})
+    accounting_date = fields.Date(string="Accounting Date", help="If set, the accounting entries created during the bank statement reconciliation process will be created at this date.\n"
+        "This is useful if the accounting period in which the entries should normally be booked is already closed.")
     state = fields.Selection([('open', 'New'), ('confirm', 'Validated')], string='Status', required=True, readonly=True, copy=False, default='open')
     currency_id = fields.Many2one('res.currency', compute='_compute_currency', oldname='currency', string="Currency")
     journal_id = fields.Many2one('account.journal', string='Journal', required=True, states={'confirm': [('readonly', True)]}, default=_default_journal)
@@ -488,7 +490,7 @@ class AccountBankStatementLine(models.Model):
             ref = move_ref + ' - ' + self.ref if move_ref else self.ref
         data = {
             'journal_id': self.statement_id.journal_id.id,
-            'date': self.date,
+            'date': self.statement_id.accounting_date or self.date,
             'ref': ref,
         }
         if self.move_name:
diff --git a/addons/account/views/account_view.xml b/addons/account/views/account_view.xml
index 00b716edb51a..3389915abc2f 100644
--- a/addons/account/views/account_view.xml
+++ b/addons/account/views/account_view.xml
@@ -644,6 +644,7 @@
                             <field name="cashbox_end_id" invisible="1"/>
                             <field name="journal_id" domain="[('type', '=', journal_type)]" attrs="{'readonly': [('move_line_count','!=', 0)]}" widget="selection"/>
                             <field name="date"/>
+                            <field name="accounting_date" groups="base.group_no_one"/>
                             <field name='company_id' options="{'no_create': True}" groups="base.group_multi_company" />
                             <field name="currency_id" invisible="1"/>
                         </group><group>
-- 
GitLab