Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] l10n_ar_account_reports: checks_to_date
closes #188 Signed-off-by: Katherine Zaoral <kz@adhoc.com.ar>
- Loading branch information
1 parent
310864e
commit 9fde6ea
Showing
7 changed files
with
294 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
l10n_ar_account_reports/reports/report_checks_to_date.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<template id="checks_to_date"> | ||
<t t-call="web.html_container"> | ||
<t t-set="company" t-value="env.company"/> | ||
<t t-call="web.internal_layout"> | ||
<h3 class="text-center">Listado de cheques pendientes al <t t-field="docs.to_date"/></h3> | ||
<t t-if="docs.journal_id"> | ||
Diario: <span t-esc="docs.env['account.journal'].browse(docs.journal_id.id).name"/> | ||
</t> | ||
<div class="page"> | ||
<br/> | ||
<h5>Cheques propios</h5> | ||
<table class="table table-sm o_main_table table-bordered"> | ||
<thead> | ||
<tr> | ||
<th class="text-left">Número</th> | ||
<th class="text-left">Fecha contable</th> | ||
<th class="text-left">Fecha de pago</th> | ||
<th class="text-left">Empresa</th> | ||
<th class="text-left">Chequera</th> | ||
<th class="text-left">Importe</th> | ||
</tr> | ||
</thead> | ||
<tbody class="sale_tbody" style="font-size: 15px"> | ||
<t t-set="total_issue" t-value="0"/> | ||
<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"/> | ||
</td> | ||
<td> | ||
<span t-field="tcheck.date"/> | ||
</td> | ||
<td> | ||
<span t-field="tcheck.l10n_latam_check_payment_date"/> | ||
</td> | ||
<td> | ||
<span t-out="tcheck.partner_id.name" /> | ||
</td> | ||
<td> | ||
<span t-out="tcheck.l10n_latam_checkbook_id.journal_id.name" /> | ||
</td> | ||
<td> | ||
<span t-out="tcheck.amount"/> | ||
</td> | ||
</tr> | ||
</tbody> | ||
<div> | ||
<td colspan="1"> | ||
<strong> | ||
<span>Total</span> | ||
</strong> | ||
</td> | ||
<td class="text-right" colspan="6"> | ||
<span t-esc="total_issue" style="font-size: 15px"/> | ||
</td> | ||
</div> | ||
</table> | ||
<br/> | ||
<h5>Cheques de terceros</h5> | ||
<table class="table table-sm o_main_table table-bordered"> | ||
<thead> | ||
<tr> | ||
<th class="text-left">Número</th> | ||
<th class="text-left">Fecha contable</th> | ||
<th class="text-left">Fecha de pago</th> | ||
<th class="text-left">Cuit</th> | ||
<th class="text-left">Importe</th> | ||
</tr> | ||
</thead> | ||
<tbody class="sale_tbody" style="font-size: 14px"> | ||
<t t-set="total" t-value="0"/> | ||
<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"/> | ||
</td> | ||
<td> | ||
<span t-field="tcheck.date"/> | ||
</td> | ||
<td> | ||
<span t-field="tcheck.l10n_latam_check_payment_date"/> | ||
</td> | ||
<td> | ||
<span t-out="tcheck.l10n_latam_check_issuer_vat" /> | ||
</td> | ||
<td> | ||
<span t-out="tcheck.amount"/> | ||
</td> | ||
</tr> | ||
</tbody> | ||
<div> | ||
<td> | ||
<strong> | ||
<span>Total</span> | ||
</strong> | ||
</td> | ||
<td class="text-right" colspan="6"> | ||
<span t-esc="total" style="font-size: 15px"/> | ||
</td> | ||
</div> | ||
</table> | ||
</div> | ||
</t> | ||
</t> | ||
</template> | ||
|
||
<record id="checks_to_date_report" model="ir.actions.report"> | ||
<field name="name">Cheques a fecha</field> | ||
<field name="model">account.check.to_date.report.wizard</field> | ||
<field name="report_type">qweb-pdf</field> | ||
<field name="report_name">l10n_ar_account_reports.checks_to_date</field> | ||
<field name="report_file">l10n_ar_account_reports.checks_to_date</field> | ||
<field name="print_report_name">'Cheques a fecha - %s' % (object.to_date)</field> | ||
</record> | ||
|
||
</odoo> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
l10n_ar_account_reports.access_account_check_to_date_report_wizard,access_account_check_to_date_report_wizard,l10n_ar_account_reports.model_account_check_to_date_report_wizard,account.group_account_invoice,1,1,1,0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import checks_to_date_report |
126 changes: 126 additions & 0 deletions
126
l10n_ar_account_reports/wizards/checks_to_date_report.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
############################################################################## | ||
# For copyright and license notices, see __manifest__.py file in module root | ||
# directory | ||
############################################################################## | ||
from odoo import models, fields, api | ||
|
||
|
||
class AccountCheckToDateReportWizard(models.TransientModel): | ||
_name = 'account.check.to_date.report.wizard' | ||
_description = 'account.check.to_date.report.wizard' | ||
|
||
journal_id = fields.Many2one( | ||
'account.journal', | ||
string='Diario', | ||
domain=[ | ||
'|', | ||
('outbound_payment_method_line_ids.code', '=', 'check_printing'), | ||
('inbound_payment_method_line_ids.code', '=', 'in_third_party_checks'), | ||
], | ||
) | ||
to_date = fields.Date( | ||
'Hasta Fecha', | ||
required=True, | ||
default=fields.Date.today, | ||
) | ||
|
||
def action_confirm(self): | ||
self.ensure_one() | ||
force_domain = self.journal_id and [('journal_id', '=', self.journal_id.id)] or [] | ||
return self.env.ref('l10n_ar_account_reports.checks_to_date_report').report_action(self) | ||
|
||
@api.model | ||
def _get_checks_handed(self, journal_id, to_date): | ||
''' | ||
hacemos una query que: | ||
* toma todos los pagos correspondientes a un cheque | ||
* dentro de esos pagos filtramos por los que no tengan matched_debit_ids | ||
* dentro de account.full.reconcile buscar todas las que tengas asocido un pago que corresponda a un cheque, una vez filtrado, | ||
* obtener la otra linea de ese full reconcile ya que esta corresponde a la conciliacion hecha en el date determinado | ||
* 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 | ||
-> 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) | ||
''' | ||
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 | ||
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 | ||
) t | ||
LEFT JOIN | ||
( | ||
SELECT ap.id as check_id, afr_full.name as conciliation_name, aml_2.date as operation_date, aml.id as aml_1, aml_2.id as aml_2 | ||
FROM account_payment ap | ||
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 | ||
) t2 | ||
ON t.check_id = t2.check_id | ||
WHERE t2.operation_date >= '%s' OR t2.operation_date IS NULL | ||
; | ||
""" % (to_date, 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)]) | ||
if journal_id: | ||
checks = self.env['account.payment'].search([('id', 'in', check_ids),('journal_id','=', journal_id)]) | ||
return checks | ||
|
||
@api.model | ||
def _get_checks_on_hand(self, journal_id, to_date): | ||
""" | ||
Hacemos una query que: | ||
* toma todos los pagos que representan un cheque | ||
* le une los pagos que representan los movimientos de esos cheques | ||
* con eso nos queda una tabla "t" que representa tods los movimientos de chques (new check, out check, in check). | ||
Con columnas payment_id, check_id, operation_date y operation_code | ||
* de esa tabla obtenemos la ultima operación anterior a la fecha que queremos analizar | ||
* si esa ultima operación NO es enviar cheque, lo consideramos en mano | ||
""" | ||
to_date = str(to_date) | ||
query = """ | ||
select check_id from ( | ||
select distinct on (check_id) check_id, operation_code, paired_code from | ||
( | ||
SELECT ap.id as payment_id, ap.id as check_id, ap_move.date as operation_date, apm.code as operation_code, pair_apm.code as paired_code | ||
FROM account_payment ap | ||
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 | ||
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 = pair_ap.payment_method_id | ||
WHERE | ||
apm.code = 'new_third_party_checks' | ||
UNION ALL | ||
SELECT ap_check_op.id as payment_id, ap_check_op.l10n_latam_check_id as check_id, ap_check_op_move.date as operation_date, apm.code as operation_code, pair_apm.code as paired_code | ||
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 | ||
) t | ||
WHERE operation_date <= '%s' order by check_id, operation_date desc, payment_id desc | ||
) t2 | ||
WHERE operation_code != 'out_third_party_checks' AND (paired_code != 'out_third_party_checks' OR paired_code IS NULL) | ||
; | ||
""" % (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)]) | ||
if journal_id: | ||
checks = self.env['account.payment'].search([('id', 'in', check_ids),('journal_id','=',journal_id)]) | ||
return checks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<odoo> | ||
<data> | ||
|
||
<record id="account_check_to_date_report_view" model="ir.ui.view"> | ||
<field name="name">account.check.to_date.report.form</field> | ||
<field name="model">account.check.to_date.report.wizard</field> | ||
<field name="arch" type="xml"> | ||
<form string="Cheques a Fecha"> | ||
<group> | ||
<field name="to_date"/> | ||
<field name="journal_id"/> | ||
</group> | ||
<footer> | ||
<button string="Confirmar" name="action_confirm" type="object" default_focus="1" class="oe_highlight"/> | ||
or | ||
<button string="Cancelar" class="oe_link" special="cancel"/> | ||
</footer> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<record id="action_account_check_to_date_report" model="ir.actions.act_window"> | ||
<field name="name">Cheques a fecha</field> | ||
<field name="res_model">account.check.to_date.report.wizard</field> | ||
<field name="target">new</field> | ||
<field name="view_mode">form</field> | ||
</record> | ||
|
||
<menuitem | ||
id="menu_account_check_to_date_report" | ||
sequence="20" | ||
parent="account.account_reports_legal_statements_menu" | ||
action="action_account_check_to_date_report" | ||
/> | ||
|
||
</data> | ||
</odoo> |