1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # account_financial_report_webkit module for OpenERP, Webkit based extended report financial report
5 # Copyright (C) 2012 SYLEAM Info Services (<http://www.syleam.fr/>)
6 # Sebastien LANGE <sebastien.lange@syleam.fr>
8 # This file is a part of account_financial_report_webkit
10 # account_financial_report_webkit is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU Affero General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
15 # account_financial_report_webkit is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU Affero General Public License for more details.
20 # You should have received a copy of the GNU Affero General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 ##############################################################################
25 from openerp
.report
import report_sxw
26 from openerp
.tools
.translate
import _
27 from openerp
import pooler
28 from datetime
import datetime
30 from common_reports
import CommonReportHeaderWebkit
31 from webkit_parser_header_fix
import HeaderFooterTextWebKitParser
34 class PrintJournalWebkit(report_sxw
.rml_parse
, CommonReportHeaderWebkit
):
36 def __init__(self
, cursor
, uid
, name
, context
):
37 super(PrintJournalWebkit
, self
).__init
__(cursor
, uid
, name
, context
=context
)
38 self
.pool
= pooler
.get_pool(self
.cr
.dbname
)
41 company_obj
= self
.pool
.get('res.company')
43 company_id
= company_obj
._company
_default
_get
(self
.cr
, uid
, 'res.users', context
=context
)
44 company
= company_obj
.browse(self
.cr
, uid
, company_id
, context
=context
)
45 header_report_name
= ' - '.join((_('JOURNALS'), company
.name
, company
.currency_id
.name
))
47 footer_date_time
= self
.formatLang(str(datetime
.today()), date_time
=True)
49 self
.localcontext
.update({
52 'report_name': _('Journals'),
53 'display_account_raw': self
._get
_display
_account
_raw
,
54 'filter_form': self
._get
_filter
,
55 'target_move': self
._get
_target
_move
,
56 'initial_balance': self
._get
_initial
_balance
,
57 'amount_currency': self
._get
_amount
_currency
,
58 'display_partner_account': self
._get
_display
_partner
_account
,
59 'display_target_move': self
._get
_display
_target
_move
,
60 'journals': self
._get
_journals
_br
,
62 ('--header-font-name', 'Helvetica'),
63 ('--footer-font-name', 'Helvetica'),
64 ('--header-font-size', '10'),
65 ('--footer-font-size', '6'),
66 ('--header-left', header_report_name
),
67 ('--header-spacing', '2'),
68 ('--footer-left', footer_date_time
),
69 ('--footer-right', ' '.join((_('Page'), '[page]', _('of'), '[topage]'))),
74 def set_context(self
, objects
, data
, ids
, report_type
=None):
75 """Populate a ledger_lines attribute on each browse record that will be used
79 main_filter
= self
._get
_form
_param
('filter', data
, default
='filter_no')
80 target_move
= self
._get
_form
_param
('target_move', data
, default
='all')
81 start_date
= self
._get
_form
_param
('date_from', data
)
82 stop_date
= self
._get
_form
_param
('date_to', data
)
83 start_period
= self
.get_start_period_br(data
)
84 stop_period
= self
.get_end_period_br(data
)
85 fiscalyear
= self
.get_fiscalyear_br(data
)
86 journal_ids
= self
._get
_form
_param
('journal_ids', data
)
87 chart_account
= self
._get
_chart
_account
_id
_br
(data
)
88 account_period_obj
= self
.pool
.get('account.period')
90 domain
= [('journal_id', 'in', journal_ids
)]
91 if main_filter
== 'filter_no':
93 ('date', '>=', self
.get_first_fiscalyear_period(fiscalyear
).date_start
),
94 ('date', '<=', self
.get_last_fiscalyear_period(fiscalyear
).date_stop
),
96 # computation of move lines
97 elif main_filter
== 'filter_date':
99 ('date', '>=', start_date
),
100 ('date', '<=', stop_date
),
102 elif main_filter
== 'filter_period':
103 period_ids
= account_period_obj
.build_ctx_periods(self
.cursor
, self
.uid
, start_period
.id, stop_period
.id)
105 ('period_id', 'in', period_ids
),
107 if target_move
== 'posted':
108 domain
+= [('state', '=', 'posted')]
109 account_journal_period_obj
= self
.pool
.get('account.journal.period')
110 new_ids
= account_journal_period_obj
.search(self
.cursor
, self
.uid
, [
111 ('journal_id', 'in', journal_ids
),
112 ('period_id', 'in', period_ids
),
114 objects
= account_journal_period_obj
.browse(self
.cursor
, self
.uid
, new_ids
)
115 # Sort by journal and period
116 objects
.sort(key
=lambda a
: (a
.journal_id
.code
, a
.period_id
.date_start
))
117 move_obj
= self
.pool
.get('account.move')
118 for journal_period
in objects
:
120 ('journal_id', '=', journal_period
.journal_id
.id),
121 ('period_id', '=', journal_period
.period_id
.id),
123 if target_move
== 'posted':
124 domain_arg
+= [('state', '=', 'posted')]
125 move_ids
= move_obj
.search(self
.cursor
, self
.uid
, domain_arg
, order
="name")
126 journal_period
.moves
= move_obj
.browse(self
.cursor
, self
.uid
, move_ids
)
127 # Sort account move line by account accountant
128 for move
in journal_period
.moves
:
129 move
.line_id
.sort(key
=lambda a
: (a
.date
, a
.account_id
.code
))
131 self
.localcontext
.update({
132 'fiscalyear': fiscalyear
,
133 'start_date': start_date
,
134 'stop_date': stop_date
,
135 'start_period': start_period
,
136 'stop_period': stop_period
,
137 'chart_account': chart_account
,
140 return super(PrintJournalWebkit
, self
).set_context(objects
, data
, new_ids
, report_type
=report_type
)
142 HeaderFooterTextWebKitParser('report.account.account_report_print_journal_webkit',
143 'account.journal.period',
144 'addons/account_financial_report_webkit/report/templates/account_report_print_journal.mako',
145 parser
=PrintJournalWebkit
)
147 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: