Skip to content

Commit

Permalink
[FIX] l10n_ar_account_reports: corregir la cantidad de diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
pablohmontenegro committed Dec 23, 2024
1 parent 8da4996 commit de3e8a3
Showing 1 changed file with 43 additions and 55 deletions.
98 changes: 43 additions & 55 deletions l10n_ar_account_reports/wizards/checks_to_date_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,33 @@ def _get_checks_handed(self, journal_id, to_date):
* entonces lo que filtramos finalmente sera, los cheques aun no fueron debitados y sean de fecha anterior a la dada o los que tiene debito luego de la fecha dada
-> en account.full.reconcile:
reconciled_line_ids.filtered(lambda x: x.move_id.payment_id.payment_method_id.code == 'own_checks').payment_id.ids -> nos da los id de los pagos correspondientes a un cheque que fueron conciliados
self.env['account.full.reconcile'].search([]).reconciled_line_ids.move_id.payment_ids.filtered(lambda x: x.payment_method_id.code == 'own_checks').ids -> nos da los id de los pagos correspondientes a un cheque que fueron conciliados
-> esto nos da en la fecha en la cual fueron debitados:
self.env['account.full.reconcile'].search([]).reconciled_line_ids.filtered(lambda x: x.move_id.matched_payment_ids.payment_method_id.code == 'own_checks')
.full_reconcile_id.reconciled_line_ids.filtered(lambda x: x.statement_line_id).mapped(lambda x: x.date)
self.env['account.full.reconcile'].search([]).reconciled_line_ids.filtered(lambda x: x.move_id.payment_ids.payment_method_id.code == 'own_checks').full_reconcile_id.reconciled_line_ids.filtered(lambda x: x.statement_line_id).mapped(lambda x: x.date)
'''
to_date = str(to_date)
query = """
SELECT DISTINCT ON (t.check_id) t.check_id AS cheque FROM
(
SELECT lc.id as check_id, ap_move.date as operation_date, apm.code as operation_code
FROM l10n_latam_check lc
JOIN account_payment AS acp ON lc.payment_id = acp.id
LEFT JOIN account_payment_method AS apm ON apm.id = acp.payment_method_id
LEFT JOIN account_move AS ap_move ON acp.move_id = ap_move.id
SELECT c.id as check_id, ap_move.date as operation_date, apm.code as operation_code
FROM l10n_latam_check c
LEFT JOIN account_payment AS ap ON c.payment_id = ap.id
LEFT JOIN account_payment_method AS apm ON apm.id = ap.payment_method_id
LEFT JOIN account_move AS ap_move ON ap.move_id = ap_move.id
LEFT JOIN account_journal AS journal ON ap_move.journal_id = journal.id
WHERE lc.issue_state = 'handed' AND apm.code = 'own_checks' AND ap_move.date <= '%s'
ORDER BY lc.id, ap_move.date DESC, lc.id DESC
WHERE
apm.code = 'own_checks' AND ap_move.date <= '%s' order by c.id, ap_move.date desc
) t
LEFT JOIN
(
SELECT lc.id as check_id, aml_2.date as operation_date, aml.id as aml_1, aml_2.id as aml_2
FROM l10n_latam_check lc
JOIN account_payment AS acp ON acp.id = lc.payment_id
JOIN account_payment_method AS apm ON apm.id = acp.payment_method_id
JOIN account_move_line AS aml ON acp.move_id = aml.move_id
SELECT c.id as check_id, aml_2.date as operation_date, aml.id as aml_1, aml_2.id as aml_2
FROM l10n_latam_check c
JOIN account_payment AS ap ON ap.id = c.payment_id
JOIN account_payment_method AS apm ON apm.id = ap.payment_method_id
JOIN account_move_line as aml ON ap.move_id = aml.move_id
JOIN account_full_reconcile AS afr_full ON afr_full.id = aml.full_reconcile_id
JOIN account_move_line AS aml_2 ON aml_2.full_reconcile_id = afr_full.id
WHERE lc.issue_state = 'debited' AND apm.code = 'own_checks' AND aml.id <> aml_2.id
WHERE apm.code = 'own_checks' AND aml.id <> aml_2.id
) t2
ON t.check_id = t2.check_id
WHERE t2.operation_date >= '%s' OR t2.operation_date IS NULL
Expand Down Expand Up @@ -97,64 +96,53 @@ def _get_checks_on_hand(self, journal_id, to_date):
SELECT DISTINCT ON (t.check_id) t.check_id AS cheque
FROM
(
SELECT lc.id as check_id, ap_move.date as operation_date, apm.code as operation_code
FROM l10n_latam_check lc
LEFT JOIN account_payment AS acp ON acp.id = lc.payment_id
LEFT JOIN account_payment_method AS apm ON apm.id = acp.payment_method_id
LEFT JOIN account_move AS ap_move ON acp.move_id = ap_move.id
SELECT c.id as check_id, ap_move.date as operation_date, apm.code as operation_code
FROM l10n_latam_check c
LEFT JOIN account_payment AS ap ON ap.id = c.payment_id
LEFT JOIN account_payment_method AS apm ON apm.id = ap.payment_method_id
LEFT JOIN account_move AS ap_move ON ap.move_id = ap_move.id
LEFT JOIN account_journal AS journal ON ap_move.journal_id = journal.id
WHERE apm.code = 'new_third_party_checks'
AND ap_move.date <= '%s'
AND lc.current_journal_id IS NOT NULL
WHERE apm.code = 'new_third_party_checks' AND ap_move.date <= '%s' AND c.current_journal_id IS NOT NULL
) t
LEFT JOIN
(
SELECT DISTINCT ON (ap_check_op.id)
ap_check_op.id as check_id,
ap_check_op.payment_id as payment_id,
ap_check_op_move.date as operation_date,
apm.code as operation_code,
ap_check_op.current_journal_id as journal,
pair_apm.code as paired_code
SELECT DISTINCT ON (ap_check_op.id) ap_check_op.id as check_id, ap_check_op.payment_id as payment_id, ap_check_op_move.date as operation_date, apm.code as operation_code, ap_check_op.current_journal_id as journal, pair_apm.code as paired_code
FROM l10n_latam_check ap_check_op
LEFT JOIN account_payment AS acp ON acp.id = ap_check_op.payment_id
LEFT JOIN account_move AS ap_check_op_move ON acp.move_id = ap_check_op_move.id
LEFT JOIN account_payment AS pair_ap ON pair_ap.id = acp.paired_internal_transfer_payment_id
LEFT JOIN account_payment_method AS apm ON apm.id = acp.payment_method_id
LEFT JOIN account_payment_method as pair_apm ON pair_apm.id = acp.payment_method_id
LEFT JOIN account_payment AS ap ON ap.id = ap_check_op.payment_id
LEFT JOIN account_move AS ap_check_op_move ON ap.move_id = ap_check_op_move.id
LEFT JOIN account_payment AS pair_ap ON pair_ap.id = ap.paired_internal_transfer_payment_id
LEFT JOIN account_payment_method AS apm ON apm.id = ap.payment_method_id
LEFT JOIN account_payment_method as pair_apm ON pair_apm.id = ap.payment_method_id
WHERE
ap_check_op_move.date <= '%s'
ORDER BY
check_id, operation_date DESC, payment_id DESC
ap_check_op_move.date <= '%s'
ORDER BY check_id, operation_date desc, payment_id desc
) t2
ON t.check_id = t2.check_id
WHERE t2.operation_date IS NULL OR (t2.operation_code != 'out_third_party_checks') AND t2.paired_code != 'out_third_party_checks'
UNION ALL
SELECT DISTINCT ON (t4.check_id) t4.check_id as cheque
FROM
(
SELECT lc.id as check_id
FROM l10n_latam_check lc
LEFT JOIN account_payment AS acp ON acp.id = lc.payment_id
LEFT JOIN account_payment_method AS apm ON apm.id = acp.payment_method_id
LEFT JOIN account_move AS ap_move ON acp.move_id = ap_move.id
SELECT c.id as check_id
FROM l10n_latam_check c
LEFT JOIN account_payment AS ap ON ap.id = c.payment_id
LEFT JOIN account_payment_method AS apm ON apm.id = ap.payment_method_id
LEFT JOIN account_move AS ap_move ON ap.move_id = ap_move.id
LEFT JOIN account_journal AS journal ON ap_move.journal_id = journal.id
WHERE
apm.code = 'out_third_party_checks'
AND ap_move.date > '%s'
AND lc.current_journal_id IS NULL
apm.code = 'out_third_party_checks' AND ap_move.date > '%s'
AND
c.current_journal_id IS NULL
) t3
JOIN
(
SELECT lc.id AS check_id, lc.current_journal_id AS journal
FROM l10n_latam_check lc
LEFT JOIN account_payment AS acp ON acp.id = lc.payment_id
LEFT JOIN account_payment_method AS apm ON apm.id = acp.payment_method_id
LEFT JOIN account_move AS ap_move ON acp.move_id = ap_move.id
SELECT c.id AS check_id, c.current_journal_id AS journal
FROM l10n_latam_check c
LEFT JOIN account_payment AS ap ON ap.id = c.payment_id
LEFT JOIN account_payment_method AS apm ON apm.id = ap.payment_method_id
LEFT JOIN account_move AS ap_move ON ap.move_id = ap_move.id
LEFT JOIN account_journal AS journal ON ap_move.journal_id = journal.id
WHERE
apm.code = 'new_third_party_checks'
AND (ap_move.date <= '%s' OR ap_move.date IS NULL)
WHERE apm.code = 'new_third_party_checks' AND (ap_move.date <= '%s' OR ap_move.date IS NULL)
) t4
ON t3.check_id = t4.check_id
WHERE t4.journal IS NULL
Expand Down

0 comments on commit de3e8a3

Please sign in to comment.