diff --git a/addons/account/models/account_journal_dashboard.py b/addons/account/models/account_journal_dashboard.py
index fc3844a9e6d..a30224b514f 100644
--- a/addons/account/models/account_journal_dashboard.py
+++ b/addons/account/models/account_journal_dashboard.py
@@ -72,6 +72,26 @@ class account_journal(models.Model):
show_on_dashboard = fields.Boolean(string='Show journal on dashboard', help="Whether this journal should be displayed on the dashboard or not", default=True)
color = fields.Integer("Color Index", default=0)
entries_count = fields.Integer(compute='_compute_entries_count')
+ has_sequence_holes = fields.Boolean(compute='_compute_has_sequence_holes')
+
+ def _query_has_sequence_holes(self):
+ self.env.cr.execute("""
+ SELECT move.journal_id,
+ move.sequence_prefix
+ FROM account_move move
+ WHERE move.journal_id = ANY(%(journal_ids)s)
+ AND move.state = 'posted'
+ GROUP BY move.journal_id, move.sequence_prefix
+ HAVING COUNT(*) != MAX(move.sequence_number) - MIN(move.sequence_number) + 1
+ """, {
+ 'journal_ids': self.ids,
+ })
+ return self.env.cr.fetchall()
+
+ def _compute_has_sequence_holes(self):
+ has_sequence_holes = set(journal_id for journal_id, _prefix in self._query_has_sequence_holes())
+ for journal in self:
+ journal.has_sequence_holes = journal.id in has_sequence_holes
def _compute_entries_count(self):
res = {
@@ -567,6 +587,23 @@ class account_journal(models.Model):
)
return action
+ def show_sequence_holes(self):
+ has_sequence_holes = self._query_has_sequence_holes()
+ return {
+ 'type': 'ir.actions.act_window',
+ 'name': _("Journal Entries"),
+ 'res_model': 'account.move',
+ 'view_mode': 'list,form',
+ 'domain': expression.OR(
+ [('journal_id', '=', journal_id), ('sequence_prefix', '=', prefix)]
+ for journal_id, prefix in has_sequence_holes
+ ),
+ 'context': {
+ 'search_default_group_by_sequence_prefix': 1,
+ 'expand': 1,
+ }
+ }
+
def create_bank_statement(self):
"""return action to create a bank statements. This button should be called only on journals with type =='bank'"""
action = self.env["ir.actions.actions"]._for_xml_id("account.action_bank_statement_tree")
diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py
index 5d03264cf87..8241a009ed9 100644
--- a/addons/account/models/account_move.py
+++ b/addons/account/models/account_move.py
@@ -143,6 +143,7 @@ class AccountMove(models.Model):
# ==== Business fields ====
name = fields.Char(string='Number', copy=False, compute='_compute_name', readonly=False, store=True, index='btree', tracking=True)
highest_name = fields.Char(compute='_compute_highest_name')
+ made_sequence_hole = fields.Boolean(compute='_compute_made_sequence_hole')
show_name_warning = fields.Boolean(store=False)
date = fields.Date(
string='Date',
@@ -1189,6 +1190,25 @@ class AccountMove(models.Model):
for record in self:
record.highest_name = record._get_last_sequence()
+ @api.depends('name', 'journal_id')
+ def _compute_made_sequence_hole(self):
+ self.env.cr.execute("""
+ SELECT this.id
+ FROM account_move this
+ LEFT JOIN account_move other ON this.journal_id = other.journal_id
+ AND this.sequence_prefix = other.sequence_prefix
+ AND this.sequence_number = other.sequence_number + 1
+ WHERE other.id IS NULL
+ AND this.sequence_number != 1
+ AND this.name != '/'
+ AND this.id = ANY(%(move_ids)s)
+ """, {
+ 'move_ids': self.ids,
+ })
+ made_sequence_hole = set(r[0] for r in self.env.cr.fetchall())
+ for move in self:
+ move.made_sequence_hole = move.id in made_sequence_hole
+
@api.onchange('name', 'highest_name')
def _onchange_name_warning(self):
if self.name and self.name != '/' and self.name <= (self.highest_name or ''):
@@ -1786,10 +1806,10 @@ class AccountMove(models.Model):
WHERE line.move_id IN %s
GROUP BY line.move_id, currency.decimal_places
)
- SELECT *
+ SELECT *
FROM error_moves
- WHERE balance !=0
- OR negative_normal
+ WHERE balance !=0
+ OR negative_normal
OR positive_storno
''', [tuple(self.ids)])
diff --git a/addons/account/views/account_journal_dashboard_view.xml b/addons/account/views/account_journal_dashboard_view.xml
index 1144688420a..646de8133b7 100644
--- a/addons/account/views/account_journal_dashboard_view.xml
+++ b/addons/account/views/account_journal_dashboard_view.xml
@@ -24,6 +24,10 @@