[IMP] account: new setting to define a start for bank reconciliation
Payments older than the chosen date won't be proposed in the widget allowing to match payments with bank statements. This is useful if the db used invoicing for years and then installed accounting : users don't want to have to match all the old payments that were generated by invoicing with bank statements. Was task 1829536 Was PR https://github.com/odoo/odoo/pull/24728
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -55,6 +55,17 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-md-6 o_setting_box">
|
||||
<div class="o_setting_left_pane"/>
|
||||
<div class="o_setting_right_pane">
|
||||
<label for="account_bank_reconciliation_start"/>
|
||||
<div class="text-muted">
|
||||
The payments which have not been matched with a bank statement will not be shown in bank reconciliation data if they were made before this date.
|
||||
</div>
|
||||
<field name="account_bank_reconciliation_start"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
<h2>Taxes</h2>
|
||||
|
||||
Reference in New Issue
Block a user