Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIG] l10n_ar_account_reports: Migration to 18.0 #458

Open
wants to merge 2 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions l10n_ar_account_reports/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
##############################################################################
{
'name': 'Accounting Reports Customized for Argentina',
'version': "17.0.1.1.0",
'version': "18.0.1.0.0",
'category': 'Accounting',
'sequence': 14,
'summary': '',
Expand All @@ -42,7 +42,7 @@
],
'test': [
],
'installable': False,
'installable': True,
'auto_install': True,
'application': False,
}
14 changes: 7 additions & 7 deletions l10n_ar_account_reports/reports/report_checks_to_date.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
<tr t-foreach="docs._get_checks_handed(docs.journal_id.id, docs.to_date)" t-as="tcheck">
<t t-set="total_issue" t-value="tcheck.amount + total_issue"/>
<td>
<span t-out="tcheck.check_number"/>
<span t-out="tcheck.name"/>
</td>
<td>
<span t-field="tcheck.date"/>
<span t-field="tcheck.payment_id.date"/>
</td>
<td>
<span t-field="tcheck.l10n_latam_check_payment_date"/>
<span t-field="tcheck.payment_date"/>
</td>
<td>
<span t-out="tcheck.partner_id.name" />
Expand Down Expand Up @@ -71,16 +71,16 @@
<tr t-foreach="docs._get_checks_on_hand(docs.journal_id.id, docs.to_date)" t-as="tcheck">
<t t-set="total" t-value="tcheck.amount + total"/>
<td>
<span t-out="tcheck.check_number"/>
<span t-out="tcheck.name"/>
</td>
<td>
<span t-field="tcheck.date"/>
<span t-field="tcheck.payment_id.date"/>
</td>
<td>
<span t-field="tcheck.l10n_latam_check_payment_date"/>
<span t-field="tcheck.payment_date"/>
</td>
<td>
<span t-out="tcheck.l10n_latam_check_issuer_vat" />
<span t-out="tcheck.issuer_vat" />
</td>
<td>
<span t-out="tcheck.amount"/>
Expand Down
65 changes: 35 additions & 30 deletions l10n_ar_account_reports/wizards/checks_to_date_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AccountCheckToDateReportWizard(models.TransientModel):
string='Diario',
domain=[
'|',
('outbound_payment_method_line_ids.code', '=', 'check_printing'),
('outbound_payment_method_line_ids.code', '=', 'own_checks'),
('inbound_payment_method_line_ids.code', '=', 'in_third_party_checks'),
],
)
Expand All @@ -40,32 +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 == 'check_printing').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.payment_id.payment_method_id.code == 'check_printing')
.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 ap.id as check_id, ap_move.date as operation_date, apm.code as operation_code
FROM account_payment ap
SELECT c.id as check_id, ap_move.date as operation_date, apm.code as operation_code
FROM l10n_latam_check c
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
apm.code = 'check_printing' AND ap_move.date <= '%s' order by ap.id, ap_move.date desc, ap.id desc
c.issue_state = 'handed' AND apm.code = 'own_checks' AND ap_move.date <= '%s' order by c.id, ap_move.date desc
) t
LEFT JOIN
(
SELECT ap.id as check_id, aml_2.date as operation_date, aml.id as aml_1, aml_2.id as aml_2
FROM account_payment ap
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 apm.code = 'check_printing' 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 All @@ -74,9 +75,9 @@ def _get_checks_handed(self, journal_id, to_date):
self.env.cr.execute(query)
res = self.env.cr.fetchall()
check_ids = [x[0] for x in res]
checks = self.env['account.payment'].search([('id', 'in', check_ids)])
checks = self.env['l10n_latam.check'].search([('id', 'in', check_ids)])
if journal_id:
checks = self.env['account.payment'].search([('id', 'in', check_ids),('journal_id','=', journal_id)])
checks = self.env['l10n_latam.check'].search([('id', 'in', check_ids), ('original_journal_id','=',journal_id)])
return checks

@api.model
Expand All @@ -95,46 +96,50 @@ def _get_checks_on_hand(self, journal_id, to_date):
SELECT DISTINCT ON (t.check_id) t.check_id AS cheque
FROM
(
SELECT ap.id as check_id, ap_move.date as operation_date, apm.code as operation_code
FROM account_payment ap
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 ap.l10n_latam_check_current_journal_id IS NOT NULL
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.l10n_latam_check_id) ap_check_op.l10n_latam_check_id as check_id, ap_check_op.id as payment_id, ap_check_op_move.date as operation_date, apm.code as operation_code, pair_apm.code as paired_code, ap_check_op.l10n_latam_check_current_journal_id as journal
FROM account_payment ap_check_op
LEFT JOIN account_move AS ap_check_op_move ON ap_check_op.move_id = ap_check_op_move.id
LEFT JOIN account_payment_method AS apm ON apm.id = ap_check_op.payment_method_id
LEFT JOIN account_payment AS pair_ap ON pair_ap.id = ap_check_op.paired_internal_transfer_payment_id
LEFT JOIN account_payment_method as pair_apm ON pair_apm.id = pair_ap.payment_method_id
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, pair_apm.code as paired_code, ap_check_op.current_journal_id as journal
FROM l10n_latam_check ap_check_op
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_method AS apm ON apm.id = ap.payment_method_id
LEFT JOIN account_payment AS pair_ap ON pair_ap.id = ap.paired_internal_transfer_payment_id
LEFT JOIN account_payment_method as pair_apm ON pair_apm.id = ap.payment_method_id
WHERE
ap_check_op.l10n_latam_check_id IS NOT NULL AND ap_check_op_move.date <= '%s'
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 paired_code != 'out_third_party_checks')
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 ap.l10n_latam_check_id as check_id
FROM account_payment ap
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
ap.l10n_latam_check_current_journal_id IS NULL
c.current_journal_id IS NULL
) t3
JOIN
(
SELECT ap.id as check_id, ap.l10n_latam_check_current_journal_id as journal
FROM account_payment ap
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
Expand All @@ -150,7 +155,7 @@ def _get_checks_on_hand(self, journal_id, to_date):
self.env.cr.execute(query)
res = self.env.cr.fetchall()
check_ids = [x[0] for x in res]
checks = self.env['account.payment'].search([('id', 'in', check_ids)])
checks = self.env['l10n_latam.check'].search([('id', 'in', check_ids)])
if journal_id:
checks = self.env['account.payment'].search([('id', 'in', check_ids),('journal_id','=',journal_id)])
checks = self.env['l10n_latam.check'].search([('id', 'in', check_ids), ('current_journal_id','=',journal_id)])
return checks