diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index ca4e6d9d370..4cc76745d96 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -302,6 +302,14 @@ class AccountMove(models.Model): if new_name: move.name = new_name + + if move == move.company_id.account_opening_move_id and not move.company_id.account_bank_reconciliation_start: + # For opening moves, we set the reconciliation date threshold + # to the move's date if it wasn't already set (we don't want + # to have to reconcile all the older payments -made before + # installing Accounting- with bank statements) + move.company_id.account_bank_reconciliation_start = move.date + return self.write({'state': 'posted'}) @api.multi diff --git a/addons/account/models/company.py b/addons/account/models/company.py index 0b5e879ce35..7e4ab7c216f 100644 --- a/addons/account/models/company.py +++ b/addons/account/models/company.py @@ -57,7 +57,10 @@ If you have any queries regarding your account, Please contact us. Thank you in advance for your cooperation. Best Regards,''')) tax_exigibility = fields.Boolean(string='Use Cash Basis') - + account_bank_reconciliation_start = fields.Date(string="Bank Reconciliation Threshold", help="""The bank reconciliation widget won't ask to reconcile payments older than this date. + This is useful if you install accounting after having used invoicing for some time and + don't want to reconcile all the past payments with bank statements.""") + incoterm_id = fields.Many2one('account.incoterms', string='Default incoterm', help='International Commercial Terms are a series of predefined commercial terms used in international transactions.') invoice_reference_type = fields.Selection(string='Default Communication Type', selection='_get_invoice_reference_types', diff --git a/addons/account/models/reconciliation_widget.py b/addons/account/models/reconciliation_widget.py index 2579d119858..e80b9ca38bf 100644 --- a/addons/account/models/reconciliation_widget.py +++ b/addons/account/models/reconciliation_widget.py @@ -471,6 +471,10 @@ class AccountReconciliation(models.AbstractModel): ]) # filter on account.move.line having the same company as the statement line domain = expression.AND([domain, [('company_id', '=', st_line.company_id.id)]]) + + if st_line.company_id.account_bank_reconciliation_start: + domain = expression.AND([domain, [('date', '>=', st_line.company_id.account_bank_reconciliation_start)]]) + return domain @api.model @@ -648,19 +652,25 @@ class AccountReconciliation(models.AbstractModel): st_line_currency = st_line.currency_id or st_line.journal_id.currency_id currency = (st_line_currency and st_line_currency != company_currency) and st_line_currency.id or False precision = st_line_currency and st_line_currency.decimal_places or company_currency.decimal_places + params = {'company_id': st_line.company_id.id, 'account_payable_receivable': (st_line.journal_id.default_credit_account_id.id, st_line.journal_id.default_debit_account_id.id), 'amount': float_repr(float_round(amount, precision_digits=precision), precision_digits=precision), 'partner_id': st_line.partner_id.id, 'excluded_ids': tuple(excluded_ids), 'ref': st_line.name, + 'bank_rec_threshold': st_line.journal_id.company_id.account_bank_reconciliation_start, } + # Look for structured communication match if st_line.name: add_to_select = ", CASE WHEN aml.ref = %(ref)s THEN 1 ELSE 2 END as temp_field_order " add_to_from = " JOIN account_move m ON m.id = aml.move_id " select_clause, from_clause, where_clause = st_line._get_common_sql_query(overlook_partner=True, excluded_ids=excluded_ids, split=True) sql_query = select_clause + add_to_select + from_clause + add_to_from + where_clause + + if params['bank_rec_threshold']: + sql_query += "AND aml.date > %(bank_rec_threshold)s" sql_query += " AND (aml.ref= %(ref)s or m.name = %(ref)s) \ ORDER BY temp_field_order, date_maturity desc, aml.id desc" self.env.cr.execute(sql_query, params) @@ -673,8 +683,10 @@ class AccountReconciliation(models.AbstractModel): liquidity_field = currency and 'amount_currency' or amount > 0 and 'debit' or 'credit' liquidity_amt_clause = currency and '%(amount)s::numeric' or 'abs(%(amount)s::numeric)' sql_query = st_line._get_common_sql_query(excluded_ids=excluded_ids) + \ - " AND (" + field + " = %(amount)s::numeric OR (acc.internal_type = 'liquidity' AND " + liquidity_field + " = " + liquidity_amt_clause + ")) \ - ORDER BY date_maturity desc, aml.id desc LIMIT 1" + " AND (" + field + " = %(amount)s::numeric OR (acc.internal_type = 'liquidity' AND " + liquidity_field + " = " + liquidity_amt_clause + "))" + if params['bank_rec_threshold']: + sql_query += "AND aml.date > %(bank_rec_threshold)s " + sql_query += "ORDER BY date_maturity desc, aml.id desc LIMIT 1" self.env.cr.execute(sql_query, params) results = self.env.cr.fetchone() if results: diff --git a/addons/account/models/res_config_settings.py b/addons/account/models/res_config_settings.py index 65085736ca2..e9926042b33 100644 --- a/addons/account/models/res_config_settings.py +++ b/addons/account/models/res_config_settings.py @@ -77,6 +77,11 @@ class ResConfigSettings(models.TransientModel): account_hide_setup_bar = fields.Boolean(string='Hide Setup Bar', related='company_id.account_setup_bar_closed',help="Tick if you wish to hide the setup bar on the dashboard") invoice_reference_type = fields.Selection(string='Communication', related='company_id.invoice_reference_type', help='Default Reference Type on Invoices.') + account_bank_reconciliation_start = fields.Date(string="Bank Reconciliation Threshold", + related='company_id.account_bank_reconciliation_start', + help="""The bank reconciliation widget won't ask to reconcile payments older than this date. + This is useful if you install accounting after having used invoicing for some time and + don't want to reconcile all the past payments with bank statements.""") @api.multi def set_values(self): diff --git a/addons/account/views/res_config_settings_views.xml b/addons/account/views/res_config_settings_views.xml index ce18cf8ee7c..b2400273a09 100644 --- a/addons/account/views/res_config_settings_views.xml +++ b/addons/account/views/res_config_settings_views.xml @@ -55,6 +55,17 @@ + +
+
+
+
+

Taxes