Skip to content

Commit

Permalink
[REF] account_move: split _get_last_sequence_domain to offer an overr…
Browse files Browse the repository at this point in the history
…ide capability to where_clause and domain
  • Loading branch information
glitchov authored and ThomasBinsfeld committed Aug 26, 2024
1 parent 7635323 commit c2dc8cc
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions addons/account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -2504,17 +2504,31 @@ def _must_check_constrains_date_sequence(self):
# OVERRIDES sequence.mixin
return not self.quick_edit_mode

def _prepare_get_last_sequence_domain(self, relaxed=False):
"""
Prepare the where clause and the domain adding a test on state to exclude draft
account moves instead of name only
:param relaxed: bool
:return: str, dict, list | None
"""
self.ensure_one()
domain = [('journal_id', '=', self.journal_id.id),
('id', '!=', self.id or self._origin.id),
('name', 'not in', ('/', '', False)),
] if not relaxed else None
where_string = "WHERE journal_id = %(journal_id)s AND name != '/'"
param = {'journal_id': self.journal_id.id}
return where_string, param, domain

def _get_last_sequence_domain(self, relaxed=False):
# EXTENDS account sequence.mixin
self.ensure_one()
if not self.date or not self.journal_id:
return "WHERE FALSE", {}
where_string = "WHERE journal_id = %(journal_id)s AND name != '/'"
param = {'journal_id': self.journal_id.id}
where_string, param, domain = self._prepare_get_last_sequence_domain(relaxed)
is_payment = self.payment_id or self._context.get('is_payment')

if not relaxed:
domain = [('journal_id', '=', self.journal_id.id), ('id', '!=', self.id or self._origin.id), ('name', 'not in', ('/', '', False))]
if self.journal_id.refund_sequence:
refund_types = ('out_refund', 'in_refund')
domain += [('move_type', 'in' if self.move_type in refund_types else 'not in', refund_types)]
Expand Down

0 comments on commit c2dc8cc

Please sign in to comment.