Skip to content

Commit

Permalink
[FIX] account_edi: Simplify payment EDI flow
Browse files Browse the repository at this point in the history
Since recent changes on account_edi, the Mexican payment flow is quite broken.
Since the payment flow has been made only for the Mexican localization,
this commit is simplifying a lot the flow to only fit the need of this localization
and resolves the introduced bugs.

closes odoo#156097

X-original-commit: d2ccea9
Related: odoo/enterprise#57927
Signed-off-by: Josse Colpaert <jco@odoo.com>
  • Loading branch information
smetl authored and jco-odoo committed Mar 1, 2024
1 parent a20da96 commit 454ab2a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
5 changes: 1 addition & 4 deletions addons/account_edi/models/account_edi_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,7 @@ def _postprocess_post_edi_results(documents, edi_result):
reconciled_lines = move.line_ids.filtered(lambda line: line.account_id.account_type in ('asset_receivable', 'liability_payable'))
reconciled_amls = reconciled_lines.mapped('matched_debit_ids.debit_move_id') \
| reconciled_lines.mapped('matched_credit_ids.credit_move_id')
reconciled_amls\
.filtered(lambda x: x.move_id.payment_id or x.move_id.statement_line_id)\
.move_id\
._update_payments_edi_documents()
reconciled_amls.move_id._update_payments_edi_documents()
else:
document.write({
'error': move_result.get('error', False),
Expand Down
22 changes: 8 additions & 14 deletions addons/account_edi/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,19 @@ def _prepare_edi_vals_to_export(self):
def _update_payments_edi_documents(self):
''' Update the edi documents linked to the current journal entries. These journal entries must be linked to an
account.payment of an account.bank.statement.line. This additional method is needed because the payment flow is
not the same as the invoice one. Indeed, the edi documents must be updated when the reconciliation with some
invoices is changing.
not the same as the invoice one. Indeed, the edi documents must be created when the payment is fully reconciled
with invoices.
'''
payments = self.filtered(lambda move: move.payment_id or move.statement_line_id)
edi_document_vals_list = []
to_remove = self.env['account.edi.document']
for payment in self:
for payment in payments:
edi_formats = payment._get_reconciled_invoices().journal_id.edi_format_ids | payment.edi_document_ids.edi_format_id
for edi_format in edi_formats:
# Only recreate document when cancelled before.
existing_edi_document = payment.edi_document_ids.filtered(lambda x: x.edi_format_id == edi_format)
if existing_edi_document.state == 'sent':
continue
move_applicability = edi_format._get_move_applicability(payment)

if move_applicability:
Expand Down Expand Up @@ -482,16 +486,6 @@ def reconcile(self):
# there is at least one reconciled invoice to the payment. Then, we need to update the state of the edi
# documents during the reconciliation.
all_lines = self + self.matched_debit_ids.debit_move_id + self.matched_credit_ids.credit_move_id
payments = all_lines.move_id.filtered(lambda move: move.payment_id or move.statement_line_id)
res = super().reconcile()
changed_payments = self.env['account.move']

for payment in payments:
amls = payment.line_ids.filtered(lambda x: x.account_id.account_type == 'asset_receivable')
if all(amls.mapped('reconciled')):
matched_invoices = payment._get_reconciled_invoices()
if all(inv.edi_state == 'sent' for inv in matched_invoices):
changed_payments |= payment
changed_payments._update_payments_edi_documents()

all_lines.move_id._update_payments_edi_documents()
return res

0 comments on commit 454ab2a

Please sign in to comment.