~serpentcs/account-financial-report/account-serpentcs

« back to all changes in this revision

Viewing changes to account_financial_report_webkit/report/print_journal.py

  • Committer: nicolas.bessi at camptocamp
  • Author(s): sebastien.lange at syleam
  • Date: 2013-09-25 06:39:36 UTC
  • mfrom: (50.1.2 account-financial-report)
  • Revision ID: nicolas.bessi@camptocamp.com-20130925063936-fdkslgwxmugi66nt
[MRG] add webkit journal report on account_financial_webkit_report

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
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>
 
7
#
 
8
#    This file is a part of account_financial_report_webkit
 
9
#
 
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.
 
14
#
 
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.
 
19
#
 
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/>.
 
22
#
 
23
##############################################################################
 
24
 
 
25
from report import report_sxw
 
26
from tools.translate import _
 
27
import pooler
 
28
from datetime import datetime
 
29
 
 
30
from common_reports import CommonReportHeaderWebkit
 
31
from webkit_parser_header_fix import HeaderFooterTextWebKitParser
 
32
 
 
33
 
 
34
class PrintJournalWebkit(report_sxw.rml_parse, CommonReportHeaderWebkit):
 
35
 
 
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)
 
39
        self.cursor = self.cr
 
40
 
 
41
        company_obj = self.pool.get('res.company')
 
42
 
 
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))
 
46
 
 
47
        footer_date_time = self.formatLang(str(datetime.today()), date_time=True)
 
48
 
 
49
        self.localcontext.update({
 
50
            'cr': cursor,
 
51
            'uid': uid,
 
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,
 
61
            'additional_args': [
 
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]'))),
 
70
                ('--footer-line',),
 
71
            ],
 
72
        })
 
73
 
 
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
 
76
        by mako template"""
 
77
 
 
78
        # Reading form
 
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')
 
89
 
 
90
        domain = [('journal_id', 'in', journal_ids)]
 
91
        if main_filter == 'filter_no':
 
92
            domain += [
 
93
                ('date', '>=', self.get_first_fiscalyear_period(fiscalyear).date_start),
 
94
                ('date', '<=', self.get_last_fiscalyear_period(fiscalyear).date_stop),
 
95
            ]
 
96
        # computation of move lines
 
97
        elif main_filter == 'filter_date':
 
98
            domain += [
 
99
                ('date', '>=', start_date),
 
100
                ('date', '<=', stop_date),
 
101
            ]
 
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)
 
104
            domain = [
 
105
                ('period_id', 'in', period_ids),
 
106
            ]
 
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),
 
113
        ])
 
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:
 
119
            domain_arg = [
 
120
                ('journal_id', '=', journal_period.journal_id.id),
 
121
                ('period_id', '=', journal_period.period_id.id),
 
122
            ]
 
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))
 
130
 
 
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,
 
138
        })
 
139
 
 
140
        return super(PrintJournalWebkit, self).set_context(objects, data, new_ids, report_type=report_type)
 
141
 
 
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)
 
146
 
 
147
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: