~openerp-community/openobject-addons/taktik

« back to all changes in this revision

Viewing changes to account/report/third_party_ledger.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:
27
27
import datetime
28
28
from report import report_sxw
29
29
 
 
30
# for report_xls
 
31
from report_xls import report_xls
 
32
import xlwt
 
33
import cStringIO
 
34
 
30
35
class third_party_ledger(rml_parse.rml_parse):
31
36
        def __init__(self, cr, uid, name, context):
32
37
                self.date_lst = []
451
456
                'addons/account/report/third_party_ledger_other.rml',parser=third_party_ledger,
452
457
                header=False)
453
458
 
 
459
 
 
460
class third_party_ledger_xls(report_xls):
 
461
 
 
462
    def create_source_xls(self, cr, uid, ids, data, report_xml, context=None):
 
463
        print("START: "+time.strftime("%Y-%m-%d %H:%M:%S"))
 
464
 
 
465
        if not context:
 
466
            context = {}
 
467
        context = context.copy()
 
468
        rml_parser = self.parser(cr, uid, self.name2, context=context)
 
469
        objs = self.getObjects(cr, uid, ids, context=context)
 
470
        rml_parser.set_context(objs, data, ids, 'xls')
 
471
 
 
472
        n = cStringIO.StringIO()
 
473
        wb = xlwt.Workbook(encoding='utf-8')
 
474
        self.generate_xls_report(rml_parser, data, rml_parser.localcontext['objects'], wb)
 
475
        wb.save(n)
 
476
        n.seek(0)
 
477
 
 
478
        print("END: "+time.strftime("%Y-%m-%d %H:%M:%S"))
 
479
 
 
480
        return (n.read(), 'xls')
 
481
 
 
482
    def generate_xls_report(self, parser, data, obj, wb):
 
483
        ws = wb.add_sheet('Partner General Ledger')
 
484
        ws.panes_frozen = True
 
485
        ws.remove_splits = True
 
486
        ws.portrait = 0 # Landscape
 
487
        ws.fit_width_to_pages = 1
 
488
 
 
489
        cols_specs = [
 
490
            # Line
 
491
            ('Date', 1, 65, 'text',
 
492
                lambda x, d, p: p.formatLang(x['date'],date=True)),
 
493
            ('JNRL', 1, 28, 'text',
 
494
                lambda x, d, p: x['code']),
 
495
            ('Ref.', 1, 45, 'text',
 
496
                lambda x, d, p: x['ref']),
 
497
            ('Entry Label', 1, 175, 'text',
 
498
                lambda x, d, p: x['name']),
 
499
            ('Debit', 1, 77, 'number',
 
500
                lambda x, d, p: x['debit']),
 
501
            ('Credit', 1, 75, 'number',
 
502
                lambda x, d, p: x['credit']),
 
503
            ('Balance', 1, 75, 'number',
 
504
                lambda x, d, p: x['progress']),
 
505
            # Partner Total
 
506
            ('Forward Name', 4, 0, 'number',
 
507
                lambda x, d, p: 'Balance Brought Forward'),
 
508
            ('Forward Balance Debit', 1, 0, 'number',
 
509
                lambda x, d, p: p._sum_debit(d)),
 
510
            ('Forward Balance Credit', 1, 0, 'number',
 
511
                lambda x, d, p: p._sum_credit(d)),
 
512
            ('Forward Balance Balance', 1, 0, 'number',
 
513
                lambda x, d, p: (p._sum_debit(d) - p._sum_credit(d)) or 0.0),
 
514
 
 
515
            # Partner Line
 
516
            ('Partner Name', 4, 0, 'text',
 
517
                lambda x, d, p: '%s%s' % (x.ref and ('%s - ' % (x.ref)) or '', x.name)),
 
518
            ('Partner Debit', 1, 0, 'number',
 
519
                lambda x, d, p: p._sum_debit_partner(x, d)),
 
520
            ('Partner Credit', 1, 0, 'number',
 
521
                lambda x, d, p: p._sum_credit_partner(x, d)),
 
522
            ('Partner Balance', 1, 0, 'number',
 
523
                lambda x, d, p: (p._sum_debit_partner(x, d) - p._sum_credit_partner(x, d)) or 0.0),
 
524
        ]
 
525
 
 
526
        hdr_line = ['Date', 'JNRL', 'Ref.', 'Entry Label', 'Debit', 'Credit', 'Balance']
 
527
        hdr_partner_total = ['Partner Name', 'Partner Debit', 'Partner Credit', 'Partner Balance']
 
528
        hdr_forward_total = [ 'Forward Name', 'Forward Balance Debit', 'Forward Balance Credit', 'Forward Balance Balance']
 
529
 
 
530
        row_line = self.xls_row_template(cols_specs, hdr_line)
 
531
        row_partner_total = self.xls_row_template(cols_specs, hdr_partner_total)
 
532
        row_forward_total = self.xls_row_template(cols_specs, hdr_forward_total)
 
533
 
 
534
        # Style
 
535
        row_hdr_style = xlwt.easyxf(
 
536
                'pattern: pattern solid, fore_color gray25;'
 
537
        )
 
538
        row_partner_style = xlwt.easyxf(
 
539
                'font: bold on;'
 
540
                'borders: bottom thin;'
 
541
        )
 
542
        row_style = xlwt.easyxf()
 
543
 
 
544
        self.xls_write_row_header(ws, 0, row_partner_total, row_hdr_style)
 
545
        self.xls_write_row_header(ws, 1, row_line, row_hdr_style, set_column_size=True)
 
546
        self.xls_write_row(ws, None, data, parser, 2, row_forward_total, row_style)
 
547
 
 
548
        row_count = 3
 
549
        ws.horz_split_pos = row_count
 
550
 
 
551
        for p in parser.objects:
 
552
            r = ws.row(row_count)
 
553
            self.xls_write_row(ws, p, data, parser,
 
554
                            row_count, row_partner_total, row_partner_style)
 
555
            row_count += 1
 
556
 
 
557
            for l in parser.lines(p, data):
 
558
                self.xls_write_row(ws, l, data, parser,
 
559
                                row_count, row_line, row_style)
 
560
                row_count += 1
 
561
 
 
562
third_party_ledger_xls('report.account.third_party_ledger_xls', 'res.partner',
 
563
        'addons/account/report/third_party_ledger.rml', parser=third_party_ledger,
 
564
        header=False)
 
565
 
454
566
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: