~openerp-community/openobject-addons/taktik

« back to all changes in this revision

Viewing changes to account/report/general_ledger_landscape.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:
37
37
global get_children_account_cache
38
38
get_children_account_cache=None
39
39
 
 
40
# for report_xls
 
41
from report_xls import report_xls
 
42
import xlwt
 
43
 
40
44
class general_ledger_landscape(rml_parse.rml_parse):
41
45
    _name = 'report.account.general.ledger_landscape'
42
46
 
419
423
        return 0.0
420
424
 
421
425
report_sxw.report_sxw('report.account.general.ledger_landscape', 'account.account', 'addons/account/report/general_ledger_landscape.rml', parser=general_ledger_landscape, header=False)
 
426
 
 
427
class general_ledger_report_xls(report_xls):
 
428
 
 
429
    def generate_xls_report(self, parser, data, obj, wb):
 
430
        """Generate report inside XLS WorkBook
 
431
        @parser: instance of report_sxw.rml_parse
 
432
        @data: wizard form data
 
433
        @obj: object on which we're going to do the reporting
 
434
        @wb: instance of xlwt.WorkBook
 
435
        """
 
436
 
 
437
        # 0: We create a new WorkSheet
 
438
        c = parser.localcontext['company']
 
439
        ws = wb.add_sheet(('General Ledger - %s' % (c.partner_id.ref))[:31])
 
440
 
 
441
        # 1: We set some worksheet properties
 
442
        ws.panes_frozen = True
 
443
        ws.remove_splits = True
 
444
        ws.portrait = 0 # Landscape
 
445
        ws.fit_width_to_pages = 1
 
446
 
 
447
        # 2: We define columns:
 
448
        #    ('Field Name', COLSPAN, COLUMN_SIZE, TYPE,
 
449
        #           get_data_function,
 
450
        #    )
 
451
        #
 
452
        #   def get_data_function(x, d, p):
 
453
        #       """ return data
 
454
        #       @x: object
 
455
        #       @d: wizard data form
 
456
        #       @p: instance of report_sxw.rml_parse
 
457
        #
 
458
        cols_specs = [
 
459
            ('Create Date', 12, 0, 'text',
 
460
                lambda x, d, p: 'Create date: ' + p.formatLang(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),date_time = True)),
 
461
            # Account summary
 
462
            ('Account', 8, 0, 'text',
 
463
                lambda x, d, p: '%s %s' % (x.code, x.name)),
 
464
            ('Account Debit', 1, 0, 'number',
 
465
                lambda x, d, p: p._sum_debit_account(x, d['form'])),
 
466
            ('Account Credit', 1, 0, 'number',
 
467
                lambda x, d, p: p._sum_credit_account(x, d['form'])),
 
468
            ('Account Balance', 1, 0, 'number',
 
469
                lambda x, d, p: p._sum_solde_account(x, d['form'])),
 
470
            ('Account Currency', 1, 0, 'text',
 
471
                lambda x, d, p: str(p._sum_currency_amount_account(x, d['form']))),
 
472
            # Move line
 
473
            ('Date', 1, 66, 'text',
 
474
                lambda x, d, p: p.formatLang(x['date'],date=True)),
 
475
            ('JNRL', 1, 35, 'text',
 
476
                lambda x, d, p: x['code']),
 
477
            ('Partner', 1, 150, 'text',
 
478
                lambda x, d, p: x['partner']),
 
479
            ('Ref', 1, 90, 'text',
 
480
                lambda x, d, p: x['ref']),
 
481
            ('Mvt', 1, 60, 'text',
 
482
                lambda x, d, p: x['move']),
 
483
            ('Reconcile', 1, 60, 'text',
 
484
                lambda x, d, p: x['reconcile_name']),
 
485
            ('Entry Label', 1, 335, 'text',
 
486
                lambda x, d, p: x['name']),
 
487
            ('Couterpart', 1, 50, 'text',
 
488
                lambda x, d, p: x['line_corresp'][:15]),
 
489
            ('Debit', 1, 70, 'number',
 
490
                lambda x, d, p: x['debit']),
 
491
            ('Credit', 1, 70, 'number',
 
492
                lambda x, d, p: x['credit']),
 
493
            ('Balance', 1, 70, 'number',
 
494
                lambda x, d, p: x['progress']),
 
495
            ('Currency', 1, 70, 'text',
 
496
                lambda x, d, p: str(x['amount_currency'] or 0.0)),
 
497
        ]
 
498
 
 
499
        # 3: Define rows templates
 
500
        hdr_acct = ['Account','Account Debit','Account Credit','Account Balance']
 
501
        hdr_acct_line = ['Date','JNRL','Partner','Ref','Mvt','Reconcile','Entry Label','Couterpart','Debit','Credit','Balance']
 
502
 
 
503
        if data.get('form',{}).get('currency',True):
 
504
            hdr_acct.append('Account Currency')
 
505
            hdr_acct_line.append('Currency')
 
506
 
 
507
        row_hdr = self.xls_row_template(cols_specs, ['Create Date'])
 
508
        row_acct = self.xls_row_template(cols_specs, hdr_acct)
 
509
        row_acct_line = self.xls_row_template(cols_specs, hdr_acct_line)
 
510
 
 
511
        # 4: Define styles
 
512
        row_hdr_style = xlwt.easyxf(
 
513
                'pattern: pattern solid, fore_color gray25;'
 
514
        )
 
515
        row_acct_style = xlwt.easyxf(
 
516
                'font: bold on;'
 
517
                'borders: bottom thin;'
 
518
        )
 
519
        row_acct_line_style = xlwt.easyxf()
 
520
 
 
521
        # 5: Write sheet header
 
522
        self.xls_write_row(ws, None, data, parser,
 
523
                           0, row_hdr, row_hdr_style)
 
524
        self.xls_write_row_header(ws, 1, row_acct, row_hdr_style)
 
525
        self.xls_write_row_header(ws, 2, row_acct_line, row_hdr_style, set_column_size=True)
 
526
 
 
527
        # 6: Freeze sheet header
 
528
        row_count = 3
 
529
        ws.horz_split_pos = row_count
 
530
 
 
531
        # 7: Loop for each lines (depends on report)
 
532
        for o in parser.get_children_accounts(obj, data['form']):
 
533
            # Display account summary
 
534
            r = ws.row(row_count)
 
535
            self.xls_write_row(ws, o, data, parser,
 
536
                               row_count, row_acct, row_acct_style)
 
537
            row_count += 1
 
538
 
 
539
            # Display each move line per account
 
540
            for l in parser.lines(o, data['form']):
 
541
                self.xls_write_row(ws, l, data, parser,
 
542
                            row_count, row_acct_line, row_acct_line_style)
 
543
                row_count += 1
 
544
 
 
545
general_ledger_report_xls('report.account.general.ledger.xls',
 
546
        'account.account',
 
547
        'addons/account/report/general_ledger_landscape.rml',
 
548
        parser=general_ledger_landscape,
 
549
        header=False)
422
550
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: