~openerp-community/openobject-addons/taktik

« back to all changes in this revision

Viewing changes to account/report/account_balance.py

  • Committer: Fabien Lydoire
  • Date: 2010-06-18 09:43:14 UTC
  • Revision ID: fl@taktik.be-20100618094314-rsei1ysqf6uwz6nf
added account reports in xls

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import time
27
27
import datetime
28
28
from report import report_sxw
 
29
from report_xls import report_xls
 
30
import xlwt
29
31
 
30
32
class account_balance(report_sxw.rml_parse):
31
33
        _name = 'report.account.account.balance'
174
176
            return self.sum_debit
175
177
 
176
178
report_sxw.report_sxw('report.account.account.balance', 'account.account', 'addons/account/report/account_balance.rml', parser=account_balance, header=False)
 
179
 
 
180
class account_balance_report_xls(report_xls):
 
181
    def generate_xls_report(self, parser, data, obj, wb):
 
182
        c = parser.localcontext['company']
 
183
        ws = wb.add_sheet(('Account Balance - %s - %s' % (c.partner_id.ref, c.currency_id.name))[:31])
 
184
        ws.panes_frozen = True
 
185
        ws.remove_splits = True
 
186
        ws.portrait = 0 # Landscape
 
187
        ws.fit_width_to_pages = 1
 
188
 
 
189
        cols_specs = [
 
190
                # Headers data
 
191
                ('Fiscal Year', 3, 0, 'text',
 
192
                    lambda x, d, p: p.get_fiscalyear(d['form'])),
 
193
                ('Create Date', 2, 0, 'text',
 
194
                    lambda x, d, p: 'Create date: ' + p.formatLang(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),date_time = True)),
 
195
                ('Periods', 5, 0, 'text',
 
196
                    lambda x, d, p: p.get_periods(d['form'])),
 
197
                # Balance column
 
198
                ('Code', 1, 67, 'text',
 
199
                    lambda x, d, p: x['code']),
 
200
                ('Account', 1, 270, 'text',
 
201
                    lambda x, d, p: '  '*x['level'] + x['name']),
 
202
                ('Debit', 1, 70, 'number',
 
203
                    lambda x, d, p: x['debit']),
 
204
                ('Credit', 1, 70, 'number',
 
205
                    lambda x, d, p: x['credit']),
 
206
                ('Balance', 1, 80, 'number',
 
207
                    lambda x, d, p: x['balance']),
 
208
        ]
 
209
 
 
210
        row_hdr1 = self.xls_row_template(cols_specs, ['Fiscal Year', 'Create Date'])
 
211
        row_hdr2 = self.xls_row_template(cols_specs, ['Periods'])
 
212
        row_balance = self.xls_row_template(cols_specs,
 
213
                ['Code','Account','Debit','Credit','Balance'])
 
214
 
 
215
        hdr_style = xlwt.easyxf('pattern: pattern solid, fore_color gray25;')
 
216
        row_normal_style=  xlwt.easyxf()
 
217
        row_bold_style = xlwt.easyxf('font: bold on;')
 
218
 
 
219
        # Write headers
 
220
        self.xls_write_row(ws, None, data, parser,
 
221
                           0, row_hdr1, hdr_style)
 
222
        self.xls_write_row(ws, None, data, parser,
 
223
                           1, row_hdr2, hdr_style)
 
224
        self.xls_write_row_header(ws, 2, row_balance, hdr_style, set_column_size=True)
 
225
 
 
226
        row_count = 3
 
227
        ws.horz_split_pos = row_count
 
228
 
 
229
        for l in parser.lines(data['form']):
 
230
            if l['level'] > 2:
 
231
                style = row_normal_style
 
232
            else:
 
233
                style = row_bold_style
 
234
 
 
235
            self.xls_write_row(ws, l, data, parser,
 
236
                        row_count, row_balance, style)
 
237
            row_count += 1
 
238
 
 
239
        pass
 
240
 
 
241
account_balance_report_xls(
 
242
        'report.account.account.balance.xls',
 
243
        'account.account',
 
244
        'addons/account/report/account_balance.rml',
 
245
        parser=account_balance,
 
246
        header=False)
 
247
 
177
248
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: