jcoux
8 years ago
8 changed files with 934 additions and 64 deletions
-
1account_financial_report_qweb/__openerp__.py
-
4account_financial_report_qweb/menuitems.xml
-
1account_financial_report_qweb/report/__init__.py
-
550account_financial_report_qweb/report/aged_partner_balance.py
-
292account_financial_report_qweb/report/templates/aged_partner_balance.xml
-
13account_financial_report_qweb/reports.xml
-
93account_financial_report_qweb/wizard/aged_partner_balance_wizard.py
-
44account_financial_report_qweb/wizard/aged_partner_balance_wizard_view.xml
@ -0,0 +1,550 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2016 Julien Coux (Camptocamp) |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from openerp import models, fields, api |
|||
|
|||
|
|||
class AgedPartnerBalanceReport(models.TransientModel): |
|||
""" Here, we just define class fields. |
|||
For methods, go more bottom at this file. |
|||
""" |
|||
|
|||
_name = 'report_aged_partner_balance_qweb' |
|||
|
|||
date_at = fields.Date() |
|||
only_posted_moves = fields.Boolean() |
|||
company_id = fields.Many2one(comodel_name='res.company') |
|||
filter_account_ids = fields.Many2many(comodel_name='account.account') |
|||
filter_partner_ids = fields.Many2many(comodel_name='res.partner') |
|||
show_move_line_details = fields.Boolean() |
|||
|
|||
open_invoice_id = fields.Many2one(comodel_name='report_open_invoice_qweb') |
|||
|
|||
account_ids = fields.One2many( |
|||
comodel_name='report_aged_partner_balance_qweb_account', |
|||
inverse_name='report_id' |
|||
) |
|||
|
|||
|
|||
class AgedPartnerBalanceAccount(models.TransientModel): |
|||
|
|||
_name = 'report_aged_partner_balance_qweb_account' |
|||
_order = 'code ASC' |
|||
|
|||
report_id = fields.Many2one( |
|||
comodel_name='report_aged_partner_balance_qweb', |
|||
ondelete='cascade', |
|||
index=True |
|||
) |
|||
account_id = fields.Many2one( |
|||
'account.account', |
|||
index=True |
|||
) |
|||
code = fields.Char() |
|||
name = fields.Char() |
|||
|
|||
cumul_amount_residual = fields.Float(digits=(16, 2)) |
|||
cumul_current = fields.Float(digits=(16, 2)) |
|||
cumul_age_30_days = fields.Float(digits=(16, 2)) |
|||
cumul_age_60_days = fields.Float(digits=(16, 2)) |
|||
cumul_age_90_days = fields.Float(digits=(16, 2)) |
|||
cumul_age_120_days = fields.Float(digits=(16, 2)) |
|||
cumul_older = fields.Float(digits=(16, 2)) |
|||
|
|||
percent_current = fields.Float(digits=(16, 2)) |
|||
percent_age_30_days = fields.Float(digits=(16, 2)) |
|||
percent_age_60_days = fields.Float(digits=(16, 2)) |
|||
percent_age_90_days = fields.Float(digits=(16, 2)) |
|||
percent_age_120_days = fields.Float(digits=(16, 2)) |
|||
percent_older = fields.Float(digits=(16, 2)) |
|||
|
|||
partner_ids = fields.One2many( |
|||
comodel_name='report_aged_partner_balance_qweb_partner', |
|||
inverse_name='report_account_id' |
|||
) |
|||
|
|||
|
|||
class AgedPartnerBalancePartner(models.TransientModel): |
|||
|
|||
_name = 'report_aged_partner_balance_qweb_partner' |
|||
|
|||
report_account_id = fields.Many2one( |
|||
comodel_name='report_aged_partner_balance_qweb_account', |
|||
ondelete='cascade', |
|||
index=True |
|||
) |
|||
partner_id = fields.Many2one( |
|||
'res.partner', |
|||
index=True |
|||
) |
|||
name = fields.Char() |
|||
|
|||
move_line_ids = fields.One2many( |
|||
comodel_name='report_aged_partner_balance_qweb_move_line', |
|||
inverse_name='report_partner_id' |
|||
) |
|||
|
|||
line_ids = fields.One2many( |
|||
comodel_name='report_aged_partner_balance_qweb_line', |
|||
inverse_name='report_partner_id' |
|||
) |
|||
|
|||
@api.model |
|||
def _generate_order_by(self, order_spec, query): |
|||
return """ |
|||
ORDER BY |
|||
CASE |
|||
WHEN "report_aged_partner_balance_qweb_partner"."partner_id" IS NOT NULL |
|||
THEN 0 |
|||
ELSE 1 |
|||
END, |
|||
"report_aged_partner_balance_qweb_partner"."name" |
|||
""" |
|||
|
|||
|
|||
class AgedPartnerBalanceLine(models.TransientModel): |
|||
|
|||
_name = 'report_aged_partner_balance_qweb_line' |
|||
|
|||
report_partner_id = fields.Many2one( |
|||
comodel_name='report_aged_partner_balance_qweb_partner', |
|||
ondelete='cascade', |
|||
index=True |
|||
) |
|||
partner = fields.Char() |
|||
amount_residual = fields.Float(digits=(16, 2)) |
|||
current = fields.Float(digits=(16, 2)) |
|||
age_30_days = fields.Float(digits=(16, 2)) |
|||
age_60_days = fields.Float(digits=(16, 2)) |
|||
age_90_days = fields.Float(digits=(16, 2)) |
|||
age_120_days = fields.Float(digits=(16, 2)) |
|||
older = fields.Float(digits=(16, 2)) |
|||
|
|||
|
|||
class AgedPartnerBalanceMoveLine(models.TransientModel): |
|||
|
|||
_name = 'report_aged_partner_balance_qweb_move_line' |
|||
|
|||
report_partner_id = fields.Many2one( |
|||
comodel_name='report_aged_partner_balance_qweb_partner', |
|||
ondelete='cascade', |
|||
index=True |
|||
) |
|||
move_line_id = fields.Many2one('account.move.line') |
|||
date = fields.Date() |
|||
date_due = fields.Date() |
|||
entry = fields.Char() |
|||
journal = fields.Char() |
|||
account = fields.Char() |
|||
partner = fields.Char() |
|||
label = fields.Char() |
|||
|
|||
amount_residual = fields.Float(digits=(16, 2)) |
|||
current = fields.Float(digits=(16, 2)) |
|||
age_30_days = fields.Float(digits=(16, 2)) |
|||
age_60_days = fields.Float(digits=(16, 2)) |
|||
age_90_days = fields.Float(digits=(16, 2)) |
|||
age_120_days = fields.Float(digits=(16, 2)) |
|||
older = fields.Float(digits=(16, 2)) |
|||
|
|||
|
|||
class AgedPartnerBalanceReportCompute(models.TransientModel): |
|||
|
|||
_inherit = 'report_aged_partner_balance_qweb' |
|||
|
|||
@api.model |
|||
def print_report(self): |
|||
self.ensure_one() |
|||
self.compute_data_for_report() |
|||
return { |
|||
'type': 'ir.actions.report.xml', |
|||
'report_name': |
|||
'account_financial_report_qweb.' |
|||
'report_aged_partner_balance_qweb', |
|||
'datas': {'ids': [self.id]}, |
|||
} |
|||
|
|||
@api.model |
|||
def compute_data_for_report(self): |
|||
self.ensure_one() |
|||
model = self.env['report_open_invoice_qweb'] |
|||
self.open_invoice_id = model.create({ |
|||
'date_at': self.date_at, |
|||
'only_posted_moves': self.only_posted_moves, |
|||
'company_id': self.company_id.id, |
|||
'filter_account_ids': [(6, 0, self.filter_account_ids.ids)], |
|||
'filter_partner_ids': [(6, 0, self.filter_partner_ids.ids)], |
|||
}) |
|||
self.open_invoice_id.compute_data_for_report() |
|||
|
|||
self.inject_account_values() |
|||
self.inject_partner_values() |
|||
self.inject_line_values() |
|||
self.inject_line_values(only_empty_partner_line=True) |
|||
if self.show_move_line_details: |
|||
self.inject_move_line_values() |
|||
self.inject_move_line_values(only_empty_partner_line=True) |
|||
self.compute_accounts_cumul() |
|||
|
|||
def inject_account_values(self): |
|||
query_inject_account = """ |
|||
INSERT INTO |
|||
report_aged_partner_balance_qweb_account |
|||
( |
|||
report_id, |
|||
create_uid, |
|||
create_date, |
|||
account_id, |
|||
code, |
|||
name |
|||
) |
|||
SELECT |
|||
%s AS report_id, |
|||
%s AS create_uid, |
|||
NOW() AS create_date, |
|||
rao.account_id, |
|||
rao.code, |
|||
rao.name |
|||
FROM |
|||
report_open_invoice_qweb_account rao |
|||
WHERE |
|||
rao.report_id = %s |
|||
""" |
|||
query_inject_account_params = ( |
|||
self.id, |
|||
self.env.uid, |
|||
self.open_invoice_id.id, |
|||
) |
|||
self.env.cr.execute(query_inject_account, query_inject_account_params) |
|||
|
|||
def inject_partner_values(self): |
|||
query_inject_partner = """ |
|||
INSERT INTO |
|||
report_aged_partner_balance_qweb_partner |
|||
( |
|||
report_account_id, |
|||
create_uid, |
|||
create_date, |
|||
partner_id, |
|||
name |
|||
) |
|||
SELECT |
|||
ra.id AS report_account_id, |
|||
%s AS create_uid, |
|||
NOW() AS create_date, |
|||
rpo.partner_id, |
|||
rpo.name |
|||
FROM |
|||
report_open_invoice_qweb_partner rpo |
|||
INNER JOIN |
|||
report_open_invoice_qweb_account rao ON rpo.report_account_id = rao.id |
|||
INNER JOIN |
|||
report_aged_partner_balance_qweb_account ra ON rao.code = ra.code |
|||
WHERE |
|||
rao.report_id = %s |
|||
AND ra.report_id = %s |
|||
""" |
|||
query_inject_partner_params = ( |
|||
self.env.uid, |
|||
self.open_invoice_id.id, |
|||
self.id, |
|||
) |
|||
self.env.cr.execute(query_inject_partner, query_inject_partner_params) |
|||
|
|||
def inject_line_values(self, only_empty_partner_line=False): |
|||
query_inject_line = """ |
|||
WITH |
|||
date_range AS |
|||
( |
|||
SELECT |
|||
%s AS date_current, |
|||
DATE %s - INTEGER '30' AS date_less_30_days, |
|||
DATE %s - INTEGER '60' AS date_less_60_days, |
|||
DATE %s - INTEGER '90' AS date_less_90_days, |
|||
DATE %s - INTEGER '120' AS date_less_120_days, |
|||
DATE %s - INTEGER '150' AS date_older |
|||
) |
|||
INSERT INTO |
|||
report_aged_partner_balance_qweb_line |
|||
( |
|||
report_partner_id, |
|||
partner, |
|||
amount_residual, |
|||
current, |
|||
age_30_days, |
|||
age_60_days, |
|||
age_90_days, |
|||
age_120_days, |
|||
older |
|||
) |
|||
SELECT |
|||
rp.id AS report_partner_id, |
|||
rp.name, |
|||
SUM(rlo.amount_residual) AS amount_residual, |
|||
SUM( |
|||
CASE |
|||
WHEN rlo.date_due > date_range.date_less_30_days |
|||
THEN rlo.amount_residual |
|||
END |
|||
) AS current, |
|||
SUM( |
|||
CASE |
|||
WHEN |
|||
rlo.date_due > date_range.date_less_60_days |
|||
AND rlo.date_due <= date_range.date_less_30_days |
|||
THEN rlo.amount_residual |
|||
END |
|||
) AS age_30_days, |
|||
SUM( |
|||
CASE |
|||
WHEN |
|||
rlo.date_due > date_range.date_less_90_days |
|||
AND rlo.date_due <= date_range.date_less_60_days |
|||
THEN rlo.amount_residual |
|||
END |
|||
) AS age_60_days, |
|||
SUM( |
|||
CASE |
|||
WHEN |
|||
rlo.date_due > date_range.date_less_120_days |
|||
AND rlo.date_due <= date_range.date_less_90_days |
|||
THEN rlo.amount_residual |
|||
END |
|||
) AS age_90_days, |
|||
SUM( |
|||
CASE |
|||
WHEN |
|||
rlo.date_due > date_range.date_older |
|||
AND rlo.date_due <= date_range.date_less_120_days |
|||
THEN rlo.amount_residual |
|||
END |
|||
) AS age_120_days, |
|||
SUM( |
|||
CASE |
|||
WHEN rlo.date_due <= date_range.date_older |
|||
THEN rlo.amount_residual |
|||
END |
|||
) AS older |
|||
FROM |
|||
date_range, |
|||
report_open_invoice_qweb_move_line rlo |
|||
INNER JOIN |
|||
report_open_invoice_qweb_partner rpo ON rlo.report_partner_id = rpo.id |
|||
INNER JOIN |
|||
report_open_invoice_qweb_account rao ON rpo.report_account_id = rao.id |
|||
INNER JOIN |
|||
report_aged_partner_balance_qweb_account ra ON rao.code = ra.code |
|||
INNER JOIN |
|||
report_aged_partner_balance_qweb_partner rp |
|||
ON |
|||
ra.id = rp.report_account_id |
|||
""" |
|||
if not only_empty_partner_line: |
|||
query_inject_line += """ |
|||
AND rpo.partner_id = rp.partner_id |
|||
""" |
|||
elif only_empty_partner_line: |
|||
query_inject_line += """ |
|||
AND rpo.partner_id IS NULL |
|||
AND rp.partner_id IS NULL |
|||
""" |
|||
query_inject_line += """ |
|||
WHERE |
|||
rao.report_id = %s |
|||
AND ra.report_id = %s |
|||
GROUP BY |
|||
rp.id |
|||
""" |
|||
query_inject_line_params = (self.date_at,) * 6 |
|||
query_inject_line_params += ( |
|||
self.open_invoice_id.id, |
|||
self.id, |
|||
) |
|||
self.env.cr.execute(query_inject_line, query_inject_line_params) |
|||
|
|||
def inject_move_line_values(self, only_empty_partner_line=False): |
|||
query_inject_move_line = """ |
|||
WITH |
|||
date_range AS |
|||
( |
|||
SELECT |
|||
%s AS date_current, |
|||
DATE %s - INTEGER '30' AS date_less_30_days, |
|||
DATE %s - INTEGER '60' AS date_less_60_days, |
|||
DATE %s - INTEGER '90' AS date_less_90_days, |
|||
DATE %s - INTEGER '120' AS date_less_120_days, |
|||
DATE %s - INTEGER '150' AS date_older |
|||
) |
|||
INSERT INTO |
|||
report_aged_partner_balance_qweb_move_line |
|||
( |
|||
report_partner_id, |
|||
date, |
|||
date_due, |
|||
entry, |
|||
journal, |
|||
account, |
|||
partner, |
|||
label, |
|||
amount_residual, |
|||
current, |
|||
age_30_days, |
|||
age_60_days, |
|||
age_90_days, |
|||
age_120_days, |
|||
older |
|||
) |
|||
SELECT |
|||
rp.id AS report_partner_id, |
|||
rlo.date, |
|||
rlo.date_due, |
|||
rlo.entry, |
|||
rlo.journal, |
|||
rlo.account, |
|||
rlo.partner, |
|||
rlo.label, |
|||
rlo.amount_residual AS amount_residual, |
|||
CASE |
|||
WHEN rlo.date_due > date_range.date_less_30_days |
|||
THEN rlo.amount_residual |
|||
END AS current, |
|||
CASE |
|||
WHEN |
|||
rlo.date_due > date_range.date_less_60_days |
|||
AND rlo.date_due <= date_range.date_less_30_days |
|||
THEN rlo.amount_residual |
|||
END AS age_30_days, |
|||
CASE |
|||
WHEN |
|||
rlo.date_due > date_range.date_less_90_days |
|||
AND rlo.date_due <= date_range.date_less_60_days |
|||
THEN rlo.amount_residual |
|||
END AS age_60_days, |
|||
CASE |
|||
WHEN |
|||
rlo.date_due > date_range.date_less_120_days |
|||
AND rlo.date_due <= date_range.date_less_90_days |
|||
THEN rlo.amount_residual |
|||
END AS age_90_days, |
|||
CASE |
|||
WHEN |
|||
rlo.date_due > date_range.date_older |
|||
AND rlo.date_due <= date_range.date_less_120_days |
|||
THEN rlo.amount_residual |
|||
END AS age_120_days, |
|||
CASE |
|||
WHEN rlo.date_due <= date_range.date_older |
|||
THEN rlo.amount_residual |
|||
END AS older |
|||
FROM |
|||
date_range, |
|||
report_open_invoice_qweb_move_line rlo |
|||
INNER JOIN |
|||
report_open_invoice_qweb_partner rpo ON rlo.report_partner_id = rpo.id |
|||
INNER JOIN |
|||
report_open_invoice_qweb_account rao ON rpo.report_account_id = rao.id |
|||
INNER JOIN |
|||
report_aged_partner_balance_qweb_account ra ON rao.code = ra.code |
|||
INNER JOIN |
|||
report_aged_partner_balance_qweb_partner rp |
|||
ON |
|||
ra.id = rp.report_account_id |
|||
""" |
|||
if not only_empty_partner_line: |
|||
query_inject_move_line += """ |
|||
AND rpo.partner_id = rp.partner_id |
|||
""" |
|||
elif only_empty_partner_line: |
|||
query_inject_move_line += """ |
|||
AND rpo.partner_id IS NULL |
|||
AND rp.partner_id IS NULL |
|||
""" |
|||
query_inject_move_line += """ |
|||
WHERE |
|||
rao.report_id = %s |
|||
AND ra.report_id = %s |
|||
""" |
|||
query_inject_move_line_params = (self.date_at,) * 6 |
|||
query_inject_move_line_params += ( |
|||
self.open_invoice_id.id, |
|||
self.id, |
|||
) |
|||
self.env.cr.execute(query_inject_move_line, |
|||
query_inject_move_line_params) |
|||
|
|||
def compute_accounts_cumul(self): |
|||
query_compute_accounts_cumul = """ |
|||
WITH |
|||
cumuls AS |
|||
( |
|||
SELECT |
|||
ra.id AS report_account_id, |
|||
SUM(rl.amount_residual) AS cumul_amount_residual, |
|||
SUM(rl.current) AS cumul_current, |
|||
SUM(rl.age_30_days) AS cumul_age_30_days, |
|||
SUM(rl.age_60_days) AS cumul_age_60_days, |
|||
SUM(rl.age_90_days) AS cumul_age_90_days, |
|||
SUM(rl.age_120_days) AS cumul_age_120_days, |
|||
SUM(rl.older) AS cumul_older |
|||
FROM |
|||
report_aged_partner_balance_qweb_line rl |
|||
INNER JOIN |
|||
report_aged_partner_balance_qweb_partner rp |
|||
ON rl.report_partner_id = rp.id |
|||
INNER JOIN |
|||
report_aged_partner_balance_qweb_account ra |
|||
ON rp.report_account_id = ra.id |
|||
WHERE |
|||
ra.report_id = %s |
|||
GROUP BY |
|||
ra.id |
|||
) |
|||
UPDATE |
|||
report_aged_partner_balance_qweb_account |
|||
SET |
|||
cumul_amount_residual = c.cumul_amount_residual, |
|||
cumul_current = c.cumul_current, |
|||
cumul_age_30_days = c.cumul_age_30_days, |
|||
cumul_age_60_days = c.cumul_age_60_days, |
|||
cumul_age_90_days = c.cumul_age_90_days, |
|||
cumul_age_120_days = c.cumul_age_120_days, |
|||
cumul_older = c.cumul_older, |
|||
percent_current = |
|||
CASE |
|||
WHEN c.cumul_amount_residual != 0 |
|||
THEN 100 * c.cumul_current / c.cumul_amount_residual |
|||
END, |
|||
percent_age_30_days = |
|||
CASE |
|||
WHEN c.cumul_amount_residual != 0 |
|||
THEN 100 * c.cumul_age_30_days / c.cumul_amount_residual |
|||
END, |
|||
percent_age_60_days = |
|||
CASE |
|||
WHEN c.cumul_amount_residual != 0 |
|||
THEN 100 * c.cumul_age_60_days / c.cumul_amount_residual |
|||
END, |
|||
percent_age_90_days = |
|||
CASE |
|||
WHEN c.cumul_amount_residual != 0 |
|||
THEN 100 * c.cumul_age_90_days / c.cumul_amount_residual |
|||
END, |
|||
percent_age_120_days = |
|||
CASE |
|||
WHEN c.cumul_amount_residual != 0 |
|||
THEN 100 * c.cumul_age_120_days / c.cumul_amount_residual |
|||
END, |
|||
percent_older = |
|||
CASE |
|||
WHEN c.cumul_amount_residual != 0 |
|||
THEN 100 * c.cumul_older / c.cumul_amount_residual |
|||
END |
|||
FROM |
|||
cumuls c |
|||
WHERE |
|||
id = c.report_account_id |
|||
""" |
|||
params_compute_accounts_cumul = (self.id,) |
|||
self.env.cr.execute(query_compute_accounts_cumul, |
|||
params_compute_accounts_cumul) |
@ -0,0 +1,292 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
|
|||
<template id="account_financial_report_qweb.report_aged_partner_balance_qweb"> |
|||
<t t-call="report.html_container"> |
|||
<t t-foreach="docs" t-as="o"> |
|||
<t t-set="show_move_line_details" t-value="o.show_move_line_details"/> |
|||
|
|||
<t t-call="account_financial_report_qweb.internal_layout"> |
|||
<t t-set="title" t-value='"Aged Partner Balance"'/> |
|||
<t t-set="company_name" t-value="o.company_id.name"/> |
|||
<div class="page"> |
|||
<div class="act_as_table data_table" style="width: 1140px !important;"> |
|||
<div class="act_as_row labels"> |
|||
<div class="act_as_cell">Date at filter</div> |
|||
<div class="act_as_cell">Target moves filter</div> |
|||
</div> |
|||
<div class="act_as_row"> |
|||
<div class="act_as_cell"> |
|||
<span t-field="o.date_at"/> |
|||
</div> |
|||
<div class="act_as_cell"> |
|||
<t t-if="o.only_posted_moves">All posted entries</t> |
|||
<t t-if="not o.only_posted_moves">All entries</t> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<t t-foreach="o.account_ids" t-as="account"> |
|||
<div class="page_break"> |
|||
<div class="act_as_table list_table" style="margin-top: 10px;"/> |
|||
<div class="act_as_caption account_title" style="width: 1141px !important;"> |
|||
<span t-field="account.code"/> - <span t-field="account.name"/> |
|||
</div> |
|||
<t t-if="not show_move_line_details"> |
|||
<div class="act_as_table data_table" style="width: 1140px !important;"> |
|||
<t t-call="account_financial_report_qweb.report_aged_partner_balance_qweb_lines_header"/> |
|||
<t t-foreach="account.partner_ids" t-as="partner"> |
|||
<t t-call="account_financial_report_qweb.report_aged_partner_balance_qweb_lines"/> |
|||
</t> |
|||
</div> |
|||
<t t-call="account_financial_report_qweb.report_aged_partner_balance_qweb_account_ending_cumul"/> |
|||
</t> |
|||
<t t-if="show_move_line_details"> |
|||
<t t-foreach="account.partner_ids" t-as="partner"> |
|||
<div class="page_break"> |
|||
<div class="act_as_caption account_title"> |
|||
<span t-field="partner.name"/> |
|||
</div> |
|||
<t t-call="account_financial_report_qweb.report_aged_partner_balance_qweb_move_lines"/> |
|||
<t t-call="account_financial_report_qweb.report_aged_partner_balance_qweb_partner_ending_cumul"> |
|||
<t t-set="partner_cumul_line" t-value="partner.line_ids"/> |
|||
</t> |
|||
</div> |
|||
</t> |
|||
<t t-call="account_financial_report_qweb.report_aged_partner_balance_qweb_account_ending_cumul"/> |
|||
</t> |
|||
</div> |
|||
</t> |
|||
</div> |
|||
</t> |
|||
</t> |
|||
</t> |
|||
</template> |
|||
|
|||
<template id="account_financial_report_qweb.report_aged_partner_balance_qweb_lines_header"> |
|||
<div class="act_as_thead"> |
|||
<div class="act_as_row labels"> |
|||
<!--## partner--> |
|||
<div class="act_as_cell" style="width: 370px;">Partner</div> |
|||
<!--## amount_residual--> |
|||
<div class="act_as_cell" style="width: 110px;">Residual</div> |
|||
<!--## current--> |
|||
<div class="act_as_cell" style="width: 110px;">Current</div> |
|||
<!--## age_30_days--> |
|||
<div class="act_as_cell" style="width: 110px;">Age ≤ 30 d.</div> |
|||
<!--## age_60_days--> |
|||
<div class="act_as_cell" style="width: 110px;">Age ≤ 60 d.</div> |
|||
<!--## age_90_days--> |
|||
<div class="act_as_cell" style="width: 110px;">Age ≤ 90 d.</div> |
|||
<!--## age_120_days--> |
|||
<div class="act_as_cell" style="width: 110px;">Age ≤ 120 d.</div> |
|||
<!--## older--> |
|||
<div class="act_as_cell" style="width: 110px;">Older</div> |
|||
</div> |
|||
</div> |
|||
</template> |
|||
|
|||
<template id="account_financial_report_qweb.report_aged_partner_balance_qweb_lines"> |
|||
<t t-foreach="partner.line_ids" t-as="line"> |
|||
<!-- # lines --> |
|||
<div class="act_as_row lines"> |
|||
<!--## partner--> |
|||
<div class="act_as_cell left"><span t-field="line.partner"/></div> |
|||
<!--## amount_residual--> |
|||
<div class="act_as_cell amount"><span t-field="line.amount_residual"/></div> |
|||
<!--## current--> |
|||
<div class="act_as_cell amount"><span t-field="line.current"/></div> |
|||
<!--## age_30_days--> |
|||
<div class="act_as_cell amount"><span t-field="line.age_30_days"/></div> |
|||
<!--## age_60_days--> |
|||
<div class="act_as_cell amount"><span t-field="line.age_60_days"/></div> |
|||
<!--## age_90_days--> |
|||
<div class="act_as_cell amount"><span t-field="line.age_90_days"/></div> |
|||
<!--## age_120_days--> |
|||
<div class="act_as_cell amount"><span t-field="line.age_120_days"/></div> |
|||
<!--## older--> |
|||
<div class="act_as_cell amount"><span t-field="line.older"/></div> |
|||
</div> |
|||
</t> |
|||
</template> |
|||
|
|||
<template id="account_financial_report_qweb.report_aged_partner_balance_qweb_move_lines"> |
|||
<div class="act_as_table data_table" style="width: 1140px !important;"> |
|||
<div class="act_as_thead"> |
|||
<div class="act_as_row labels"> |
|||
<!--## date--> |
|||
<div class="act_as_cell first_column" style="width: 60px;">Date</div> |
|||
<!--## move--> |
|||
<div class="act_as_cell" style="width: 100px;">Entry</div> |
|||
<!--## journal--> |
|||
<div class="act_as_cell" style="width: 40px;">Journal</div> |
|||
<!--## account code--> |
|||
<div class="act_as_cell" style="width: 50px;">Account</div> |
|||
<!--## partner--> |
|||
<div class="act_as_cell" style="width: 120px;">Partner</div> |
|||
<!--## ref - label--> |
|||
<div class="act_as_cell" style="width: 220px;">Ref - Label</div> |
|||
<!--## date_due--> |
|||
<div class="act_as_cell" style="width: 60px;">Due date</div> |
|||
<!--## amount_residual--> |
|||
<div class="act_as_cell" style="width: 70px;">Residual</div> |
|||
<!--## current--> |
|||
<div class="act_as_cell" style="width: 70px;">Current</div> |
|||
<!--## age_30_days--> |
|||
<div class="act_as_cell" style="width: 70px;">Age ≤ 30 d.</div> |
|||
<!--## age_60_days--> |
|||
<div class="act_as_cell" style="width: 70px;">Age ≤ 60 d.</div> |
|||
<!--## age_90_days--> |
|||
<div class="act_as_cell" style="width: 70px;">Age ≤ 90 d.</div> |
|||
<!--## age_120_days--> |
|||
<div class="act_as_cell" style="width: 70px;">Age ≤ 120 d.</div> |
|||
<!--## older--> |
|||
<div class="act_as_cell" style="width: 70px;">Older</div> |
|||
</div> |
|||
</div> |
|||
<t t-foreach="partner.move_line_ids" t-as="line"> |
|||
<!-- # lines or centralized lines --> |
|||
<div class="act_as_row lines"> |
|||
<!--## date--> |
|||
<div class="act_as_cell left"><span t-field="line.date"/></div> |
|||
<!--## move--> |
|||
<div class="act_as_cell left"><span t-field="line.entry"/></div> |
|||
<!--## journal--> |
|||
<div class="act_as_cell left"><span t-field="line.journal"/></div> |
|||
<!--## account code--> |
|||
<div class="act_as_cell left"><span t-field="line.account"/></div> |
|||
<!--## partner--> |
|||
<div class="act_as_cell left"><span t-field="line.partner"/></div> |
|||
<!--## ref - label--> |
|||
<div class="act_as_cell left"><span t-field="line.label"/></div> |
|||
<!--## date_due--> |
|||
<div class="act_as_cell left"><span t-field="line.date_due"/></div> |
|||
<!--## amount_residual--> |
|||
<div class="act_as_cell amount"><span t-field="line.amount_residual"/></div> |
|||
<!--## current--> |
|||
<div class="act_as_cell amount"><span t-field="line.current"/></div> |
|||
<!--## age_30_days--> |
|||
<div class="act_as_cell amount"><span t-field="line.age_30_days"/></div> |
|||
<!--## age_60_days--> |
|||
<div class="act_as_cell amount"><span t-field="line.age_60_days"/></div> |
|||
<!--## age_90_days--> |
|||
<div class="act_as_cell amount"><span t-field="line.age_90_days"/></div> |
|||
<!--## age_120_days--> |
|||
<div class="act_as_cell amount"><span t-field="line.age_120_days"/></div> |
|||
<!--## older--> |
|||
<div class="act_as_cell amount"><span t-field="line.older"/></div> |
|||
</div> |
|||
</t> |
|||
</div> |
|||
</template> |
|||
|
|||
<template id="account_financial_report_qweb.report_aged_partner_balance_qweb_partner_ending_cumul"> |
|||
<div class="act_as_table list_table" style="width: 1141px !important;"> |
|||
<div class="act_as_row labels" style="font-weight: bold;"> |
|||
<!--## date--> |
|||
<div class="act_as_cell right" style="width: 590px;">Partner cumul aged balance</div> |
|||
<!--## date_due--> |
|||
<div class="act_as_cell" style="width: 60px;"/> |
|||
<!--## amount_residual--> |
|||
<div class="act_as_cell amount" style="width: 70px;"><span t-field="partner_cumul_line.amount_residual"/></div> |
|||
<!--## current--> |
|||
<div class="act_as_cell amount" style="width: 70px;"><span t-field="partner_cumul_line.current"/></div> |
|||
<!--## age_30_days--> |
|||
<div class="act_as_cell amount" style="width: 70px;"><span t-field="partner_cumul_line.age_30_days"/></div> |
|||
<!--## age_60_days--> |
|||
<div class="act_as_cell amount" style="width: 70px;"><span t-field="partner_cumul_line.age_60_days"/></div> |
|||
<!--## age_90_days--> |
|||
<div class="act_as_cell amount" style="width: 70px;"><span t-field="partner_cumul_line.age_90_days"/></div> |
|||
<!--## age_120_days--> |
|||
<div class="act_as_cell amount" style="width: 70px;"><span t-field="partner_cumul_line.age_120_days"/></div> |
|||
<!--## older--> |
|||
<div class="act_as_cell amount" style="width: 70px;"><span t-field="partner_cumul_line.older"/></div> |
|||
</div> |
|||
</div> |
|||
</template> |
|||
|
|||
<template id="account_financial_report_qweb.report_aged_partner_balance_qweb_account_ending_cumul"> |
|||
<div class="act_as_table list_table" style="width: 1141px !important;"> |
|||
<div class="act_as_row labels" style="font-weight: bold;"> |
|||
<t t-if="not show_move_line_details"> |
|||
<!--## total--> |
|||
<div class="act_as_cell right" style="width: 370px;">Total</div> |
|||
<!--## amount_residual--> |
|||
<div class="act_as_cell amount" style="width: 110px;"><span t-field="account.cumul_amount_residual"/></div> |
|||
<!--## current--> |
|||
<div class="act_as_cell amount" style="width: 110px;"><span t-field="account.cumul_current"/></div> |
|||
<!--## age_30_days--> |
|||
<div class="act_as_cell amount" style="width: 110px;"><span t-field="account.cumul_age_30_days"/></div> |
|||
<!--## age_60_days--> |
|||
<div class="act_as_cell amount" style="width: 110px;"><span t-field="account.cumul_age_60_days"/></div> |
|||
<!--## age_90_days--> |
|||
<div class="act_as_cell amount" style="width: 110px;"><span t-field="account.cumul_age_90_days"/></div> |
|||
<!--## age_120_days--> |
|||
<div class="act_as_cell amount" style="width: 110px;"><span t-field="account.cumul_age_120_days"/></div> |
|||
<!--## older--> |
|||
<div class="act_as_cell amount" style="width: 110px;"><span t-field="account.cumul_older"/></div> |
|||
</t> |
|||
<t t-if="show_move_line_details"> |
|||
<!--## total--> |
|||
<div class="act_as_cell right" style="width: 590px;">Total</div> |
|||
<!--## date_due--> |
|||
<div class="act_as_cell" style="width: 60px;"/> |
|||
<!--## amount_residual--> |
|||
<div class="act_as_cell amount" style="width: 70px;"><span t-field="account.cumul_amount_residual"/></div> |
|||
<!--## current--> |
|||
<div class="act_as_cell amount" style="width: 70px;"><span t-field="account.cumul_current"/></div> |
|||
<!--## age_30_days--> |
|||
<div class="act_as_cell amount" style="width: 70px;"><span t-field="account.cumul_age_30_days"/></div> |
|||
<!--## age_60_days--> |
|||
<div class="act_as_cell amount" style="width: 70px;"><span t-field="account.cumul_age_60_days"/></div> |
|||
<!--## age_90_days--> |
|||
<div class="act_as_cell amount" style="width: 70px;"><span t-field="account.cumul_age_90_days"/></div> |
|||
<!--## age_120_days--> |
|||
<div class="act_as_cell amount" style="width: 70px;"><span t-field="account.cumul_age_120_days"/></div> |
|||
<!--## older--> |
|||
<div class="act_as_cell amount" style="width: 70px;"><span t-field="account.cumul_older"/></div> |
|||
</t> |
|||
</div> |
|||
<div class="act_as_row" style="font-weight: bold; font-style: italic;"> |
|||
<t t-if="not show_move_line_details"> |
|||
<!--## total--> |
|||
<div class="act_as_cell right" style="width: 370px;">Percents</div> |
|||
<!--## amount_residual--> |
|||
<div class="act_as_cell amount" style="width: 110px;"></div> |
|||
<!--## current--> |
|||
<div class="act_as_cell amount" style="width: 110px;"><span t-field="account.percent_current"/>%</div> |
|||
<!--## age_30_days--> |
|||
<div class="act_as_cell amount" style="width: 110px;"><span t-field="account.percent_age_30_days"/>%</div> |
|||
<!--## age_60_days--> |
|||
<div class="act_as_cell amount" style="width: 110px;"><span t-field="account.percent_age_60_days"/>%</div> |
|||
<!--## age_90_days--> |
|||
<div class="act_as_cell amount" style="width: 110px;"><span t-field="account.percent_age_90_days"/>%</div> |
|||
<!--## age_120_days--> |
|||
<div class="act_as_cell amount" style="width: 110px;"><span t-field="account.percent_age_120_days"/>%</div> |
|||
<!--## older--> |
|||
<div class="act_as_cell amount" style="width: 110px;"><span t-field="account.percent_older"/>%</div> |
|||
</t> |
|||
<t t-if="show_move_line_details"> |
|||
<!--## total--> |
|||
<div class="act_as_cell right" style="width: 590px;">Percents</div> |
|||
<!--## date_due--> |
|||
<div class="act_as_cell" style="width: 60px;"/> |
|||
<!--## amount_residual--> |
|||
<div class="act_as_cell amount" style="width: 70px;"></div> |
|||
<!--## current--> |
|||
<div class="act_as_cell amount" style="width: 70px;"><span t-field="account.percent_current"/>%</div> |
|||
<!--## age_30_days--> |
|||
<div class="act_as_cell amount" style="width: 70px;"><span t-field="account.percent_age_30_days"/>%</div> |
|||
<!--## age_60_days--> |
|||
<div class="act_as_cell amount" style="width: 70px;"><span t-field="account.percent_age_60_days"/>%</div> |
|||
<!--## age_90_days--> |
|||
<div class="act_as_cell amount" style="width: 70px;"><span t-field="account.percent_age_90_days"/>%</div> |
|||
<!--## age_120_days--> |
|||
<div class="act_as_cell amount" style="width: 70px;"><span t-field="account.percent_age_120_days"/>%</div> |
|||
<!--## older--> |
|||
<div class="act_as_cell amount" style="width: 70px;"><span t-field="account.percent_older"/>%</div> |
|||
</t> |
|||
</div> |
|||
</div> |
|||
</template> |
|||
|
|||
</odoo> |
@ -1,66 +1,75 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Author: Damien Crier, Andrea Stirpe, Kevin Graveman, Dennis Sluijk |
|||
# Author: Julien Coux |
|||
# Copyright 2016 Camptocamp SA, Onestein B.V. |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from datetime import datetime |
|||
from openerp.exceptions import Warning as UserError |
|||
from openerp import api, fields, models |
|||
|
|||
|
|||
class AccountAgedTrialBalance(models.TransientModel): |
|||
class AgedPartnerBalance(models.TransientModel): |
|||
"""Aged partner balance report wizard.""" |
|||
|
|||
_name = 'account.aged.trial.balance.wizard' |
|||
_description = 'Aged partner balanced' |
|||
_name = 'aged.partner.balance.wizard' |
|||
_description = 'Aged Partner Balance Wizard' |
|||
|
|||
company_id = fields.Many2one( |
|||
'res.company', |
|||
string='Company', |
|||
required=True, |
|||
default=lambda s: s.env.user.company_id |
|||
comodel_name='res.company', |
|||
default=lambda self: self.env.user.company_id |
|||
) |
|||
date_at = fields.Date(required=True, |
|||
default=fields.Date.to_string(datetime.today())) |
|||
target_move = fields.Selection([('posted', 'All Posted Entries'), |
|||
('all', 'All Entries')], |
|||
string='Target Moves', |
|||
required=True, |
|||
default='posted') |
|||
result_selection = fields.Selection( |
|||
[('customer', 'Receivable Accounts'), |
|||
('supplier', 'Payable Accounts'), |
|||
('customer_supplier', 'Receivable and Payable Accounts') |
|||
], |
|||
string="Partner's", |
|||
default='customer') |
|||
default='all') |
|||
account_ids = fields.Many2many( |
|||
comodel_name='account.account', |
|||
string='Filter accounts', |
|||
) |
|||
receivable_accounts_only = fields.Boolean() |
|||
payable_accounts_only = fields.Boolean() |
|||
partner_ids = fields.Many2many( |
|||
'res.partner', |
|||
comodel_name='res.partner', |
|||
string='Filter partners', |
|||
) |
|||
at_date = fields.Date( |
|||
required=True, |
|||
default=fields.Date.to_string(datetime.today())) |
|||
until_date = fields.Date( |
|||
"Clearance date", required=True, |
|||
help="""The clearance date is essentially a tool used for debtors |
|||
provisionning calculation. |
|||
By default, this date is equal to the the end date ( |
|||
ie: 31/12/2011 if you select fy 2011). |
|||
By amending the clearance date, you will be, for instance, |
|||
able to answer the question : 'based on my last |
|||
year end debtors open invoices, which invoices are still |
|||
unpaid today (today is my clearance date)?'""") |
|||
show_move_line_details = fields.Boolean() |
|||
|
|||
@api.onchange('at_date') |
|||
def onchange_atdate(self): |
|||
self.until_date = self.at_date |
|||
@api.onchange('date_range_id') |
|||
def onchange_date_range_id(self): |
|||
"""Handle date range change.""" |
|||
self.date_at = self.date_range_id.date_end |
|||
if self.date_range_id.date_start: |
|||
self.fy_start_date = self.env.user.company_id.find_daterange_fy( |
|||
fields.Date.from_string(self.date_range_id.date_start) |
|||
).date_start |
|||
|
|||
@api.onchange('until_date') |
|||
def onchange_untildate(self): |
|||
# ---- until_date must be always >= of at_date |
|||
if self.until_date: |
|||
if self.until_date < self.at_date: |
|||
raise UserError( |
|||
'Until Date must be equal or greater than At Date') |
|||
@api.onchange('receivable_accounts_only', 'payable_accounts_only') |
|||
def onchange_type_accounts_only(self): |
|||
"""Handle receivable/payable accounts only change.""" |
|||
if self.receivable_accounts_only or self.payable_accounts_only: |
|||
domain = [] |
|||
if self.receivable_accounts_only and self.payable_accounts_only: |
|||
domain += [('internal_type', 'in', ('receivable', 'payable'))] |
|||
elif self.receivable_accounts_only: |
|||
domain += [('internal_type', '=', 'receivable')] |
|||
elif self.payable_accounts_only: |
|||
domain += [('internal_type', '=', 'payable')] |
|||
self.account_ids = self.env['account.account'].search(domain) |
|||
else: |
|||
self.account_ids = None |
|||
|
|||
@api.multi |
|||
def check_report(self): |
|||
return True |
|||
def button_export_pdf(self): |
|||
model = self.env['report_aged_partner_balance_qweb'] |
|||
report = model.create({ |
|||
'date_at': self.date_at, |
|||
'only_posted_moves': self.target_move == 'posted', |
|||
'company_id': self.company_id.id, |
|||
'filter_account_ids': [(6, 0, self.account_ids.ids)], |
|||
'filter_partner_ids': [(6, 0, self.partner_ids.ids)], |
|||
'show_move_line_details': self.show_move_line_details, |
|||
}) |
|||
return report.print_report() |
Write
Preview
Loading…
Cancel
Save
Reference in new issue