Skip to content

Commit

Permalink
[IMP] account: Allow to extend select of communication_flag
Browse files Browse the repository at this point in the history
communication_flag in the SELECT is used to determine candidates for automatic reconciliation.
Extracting this part allows to customize the behaviour implied by the use of match_total_amount and specifically the warning "This parameter will be bypassed in case of a statement line communication matching exactly existing entries" to avoid an automatic reconciliation when the amount doesn't match.

closes odoo#52731

Signed-off-by: oco-odoo <[email protected]>
  • Loading branch information
fw-bot authored and oco-odoo committed Jun 15, 2020
1 parent 65d89ad commit 23d8413
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions addons/account/models/account_reconcile_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,33 +535,7 @@ def _get_invoice_matching_query(self, st_lines_with_partner, excluded_ids):
aml.amount_currency AS aml_amount_currency,
account.internal_type AS account_internal_type,
-- Determine a matching or not with the statement line communication using the aml.name, move.name or move.ref.
(
aml.name IS NOT NULL
AND
substring(REGEXP_REPLACE(aml.name, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*') != ''
AND
regexp_split_to_array(substring(REGEXP_REPLACE(aml.name, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'),'\s+')
&& regexp_split_to_array(substring(REGEXP_REPLACE(st_line.payment_ref, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'), '\s+')
)
OR
regexp_split_to_array(substring(REGEXP_REPLACE(move.name, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'),'\s+')
&& regexp_split_to_array(substring(REGEXP_REPLACE(st_line.payment_ref, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'), '\s+')
OR
(
move.ref IS NOT NULL
AND
substring(REGEXP_REPLACE(move.ref, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*') != ''
AND
regexp_split_to_array(substring(REGEXP_REPLACE(move.ref, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'),'\s+')
&& regexp_split_to_array(substring(REGEXP_REPLACE(st_line.payment_ref, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'), '\s+')
) AS communication_flag,
-- Determine a matching or not with the statement line communication using the move.payment_reference.
(
move.payment_reference IS NOT NULL
AND
regexp_replace(move.payment_reference, '\s+', '', 'g') = regexp_replace(st_line.payment_ref, '\s+', '', 'g')
) AS payment_reference_flag
''' + self._get_select_communication_flag() + r''', ''' + self._get_select_payment_reference_flag() + r'''
FROM account_bank_statement_line st_line
JOIN account_move st_line_move ON st_line_move.id = st_line.move_id
JOIN account_journal journal ON journal.id = st_line_move.journal_id
Expand Down Expand Up @@ -663,6 +637,41 @@ def _get_invoice_matching_query(self, st_lines_with_partner, excluded_ids):

return query, params

def _get_select_communication_flag(self):
return r'''
-- Determine a matching or not with the statement line communication using the aml.name, move.name or move.ref.
(
aml.name IS NOT NULL
AND
substring(REGEXP_REPLACE(aml.name, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*') != ''
AND
regexp_split_to_array(substring(REGEXP_REPLACE(aml.name, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'),'\s+')
&& regexp_split_to_array(substring(REGEXP_REPLACE(st_line.payment_ref, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'), '\s+')
)
OR
regexp_split_to_array(substring(REGEXP_REPLACE(move.name, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'),'\s+')
&& regexp_split_to_array(substring(REGEXP_REPLACE(st_line.payment_ref, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'), '\s+')
OR
(
move.ref IS NOT NULL
AND
substring(REGEXP_REPLACE(move.ref, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*') != ''
AND
regexp_split_to_array(substring(REGEXP_REPLACE(move.ref, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'),'\s+')
&& regexp_split_to_array(substring(REGEXP_REPLACE(st_line.payment_ref, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'), '\s+')
) AS communication_flag
'''

def _get_select_payment_reference_flag(self):
return r'''
-- Determine a matching or not with the statement line communication using the move.payment_reference.
(
move.payment_reference IS NOT NULL
AND
regexp_replace(move.payment_reference, '\s+', '', 'g') = regexp_replace(st_line.payment_ref, '\s+', '', 'g')
) AS payment_reference_flag
'''

def _get_partner_from_mapping(self, st_line):
""" For invoice matching rules, matches the statement line against
each regex defined in partner mapping, and returns the partner corresponding to
Expand Down

0 comments on commit 23d8413

Please sign in to comment.