~bcim/account-invoicing/saas1-belgium

« back to all changes in this revision

Viewing changes to account_move_line_report_xls/report/move_line_list_xls.py

  • Committer: openerp
  • Date: 2013-06-30 19:22:59 UTC
  • Revision ID: openerp@oerp70-20130630192259-3desy9ff4qozf9ls
update noviat V7.0 modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    
 
6
#    Copyright (c) 2013 Noviat nv/sa (www.noviat.be). All rights reserved.
 
7
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU Affero General Public License as
 
10
#    published by the Free Software Foundation, either version 3 of the
 
11
#    License, or (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU Affero General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU Affero General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
import xlwt
 
24
import time
 
25
from datetime import datetime
 
26
from report import report_sxw
 
27
from report_xls.report_xls import report_xls
 
28
from report_xls.utils import rowcol_to_cell
 
29
from account_move_line_report.report.move_line_list_print import move_line_list_print
 
30
from tools.translate import _
 
31
import logging
 
32
_logger = logging.getLogger(__name__)
 
33
 
 
34
class move_line_xls(report_xls):
 
35
    
 
36
    def generate_xls_report(self, _p, _xs, data, objects, wb):
 
37
 
 
38
        report_name = objects[0]._description or objects[0]._name
 
39
        ws = wb.add_sheet(report_name[:31])
 
40
        ws.panes_frozen = True
 
41
        ws.remove_splits = True
 
42
        ws.portrait = 0 # Landscape
 
43
        ws.fit_width_to_pages = 1
 
44
        row_pos = 0
 
45
        
 
46
        # set print header/footer
 
47
        ws.header_str = self.xls_headers['standard']
 
48
        ws.footer_str = self.xls_footers['standard']
 
49
 
 
50
        # Title
 
51
        cell_style = xlwt.easyxf(_xs['xls_title'])
 
52
        c_specs = [
 
53
            ('report_name', 1, 0, 'text', report_name),
 
54
        ]       
 
55
        row_data = self.xls_row_template(c_specs, ['report_name'])
 
56
        row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style)
 
57
        row_pos += 1
 
58
 
 
59
        # Column headers
 
60
        rh_cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all']
 
61
        rh_cell_style = xlwt.easyxf(rh_cell_format)
 
62
        rh_cell_style_center = xlwt.easyxf(rh_cell_format + _xs['center'])
 
63
        rh_cell_style_right = xlwt.easyxf(rh_cell_format + _xs['right'])  
 
64
        c_specs = [
 
65
            ('move', 1, 20, 'text', _('Move')),
 
66
            ('name', 1, 42, 'text', _('Name')),
 
67
            ('date', 1, 13, 'text', _('Effective Date')),
 
68
            ('period', 1, 12, 'text', _('Period')),
 
69
            ('partner', 1, 36, 'text',  _('Partner')),
 
70
            ('account', 1, 12, 'text',  _('Account')),
 
71
            ('maturity', 1, 13, 'text',  _('Maturity Date')),
 
72
            ('debit', 1, 18, 'text',  _('Debit'), None, rh_cell_style_right),
 
73
            ('credit', 1, 18, 'text',  _('Credit'), None, rh_cell_style_right),
 
74
            ('balance', 1, 18, 'text',   _('Balance'), None, rh_cell_style_right),
 
75
            ('reconcile', 1, 12, 'text',  _('Rec.'), None, rh_cell_style_center),
 
76
            ('reconcile_partial', 1, 12, 'text',  _('Part. Rec.'), None, rh_cell_style_center),
 
77
        ]       
 
78
        row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
 
79
        row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=rh_cell_style, set_column_size=True)        
 
80
        ws.set_horz_split_pos(row_pos)   
 
81
        
 
82
        # account move lines
 
83
        aml_cell_format = _xs['borders_all']
 
84
        aml_cell_style = xlwt.easyxf(aml_cell_format)
 
85
        aml_cell_style_center = xlwt.easyxf(aml_cell_format + _xs['center'])
 
86
        aml_cell_style_date = xlwt.easyxf(aml_cell_format + _xs['left'], num_format_str = report_xls.date_format)
 
87
        aml_cell_style_decimal = xlwt.easyxf(aml_cell_format + _xs['right'], num_format_str = report_xls.decimal_format)
 
88
        for line in objects:
 
89
            debit_cell = rowcol_to_cell(row_pos, 7)
 
90
            credit_cell = rowcol_to_cell(row_pos, 8)
 
91
            bal_formula = debit_cell + '-' + credit_cell
 
92
            c_specs = [
 
93
                ('move', 1, 0, 'text', line.move_id.name or ''),
 
94
                ('name', 1, 0, 'text', line.name or ''),
 
95
                ('date', 1, 0, 'date', datetime.strptime(line.date,'%Y-%m-%d'), None, aml_cell_style_date),
 
96
                ('period', 1, 0, 'text', line.period_id.code or ''),
 
97
                ('partner', 1, 0, 'text', line.partner_id and line.partner_id.name or ''),
 
98
                ('account', 1, 0, 'text', line.account_id.code),
 
99
            ]
 
100
            if line.date_maturity.val:
 
101
                c_specs += [
 
102
                    ('maturity', 1, 0, 'date', datetime.strptime(line.date_maturity,'%Y-%m-%d'), None, aml_cell_style_date),
 
103
                ]
 
104
            else:
 
105
                c_specs += [
 
106
                    ('maturity', 1, 0, 'text', None),
 
107
                ]                                  
 
108
            c_specs += [
 
109
                ('debit', 1, 0, 'number', line.debit, None, aml_cell_style_decimal),
 
110
                ('credit', 1, 0, 'number', line.credit, None, aml_cell_style_decimal),
 
111
                ('balance', 1, 0, 'number', None, bal_formula, aml_cell_style_decimal),
 
112
                ('reconcile', 1, 0, 'text', line.reconcile_id.name or '', None, aml_cell_style_center),                
 
113
                ('reconcile_partial', 1, 0, 'text', line.reconcile_partial_id.name or '', None, aml_cell_style_center),                
 
114
            ]
 
115
            row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
 
116
            row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=aml_cell_style)
 
117
 
 
118
        # Totals           
 
119
        rt_cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all']
 
120
        rt_cell_style = xlwt.easyxf(rt_cell_format)
 
121
        rt_cell_style_right = xlwt.easyxf(rt_cell_format + _xs['right'])       
 
122
        rt_cell_style_decimal = xlwt.easyxf(rt_cell_format + _xs['right'], num_format_str = report_xls.decimal_format)
 
123
 
 
124
        aml_cnt = len(objects)
 
125
        debit_start = rowcol_to_cell(row_pos - aml_cnt, 7)
 
126
        debit_stop = rowcol_to_cell(row_pos - 1, 7)
 
127
        debit_formula = 'SUM(%s:%s)' %(debit_start, debit_stop)
 
128
        credit_start = rowcol_to_cell(row_pos - aml_cnt, 8)
 
129
        credit_stop = rowcol_to_cell(row_pos - 1, 8)
 
130
        credit_formula = 'SUM(%s:%s)' %(credit_start, credit_stop)
 
131
        debit_cell = rowcol_to_cell(row_pos, 7)
 
132
        credit_cell = rowcol_to_cell(row_pos, 8)
 
133
        bal_formula = debit_cell + '-' + credit_cell
 
134
 
 
135
        c_specs = [('empty%s'%i, 1, 0, 'text', None) for i in range(1,8)] 
 
136
        c_specs += [
 
137
            ('debit', 1, 0, 'number', None, debit_formula, rt_cell_style_decimal),
 
138
            ('credit', 1, 0, 'number', None, credit_formula, rt_cell_style_decimal),
 
139
            ('balance', 1, 0, 'number', None, bal_formula, rt_cell_style_decimal),
 
140
        ]       
 
141
        c_specs += [('empty%s'%i, 1, 0, 'text', None) for i in range(11,13)] 
 
142
        row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
 
143
        row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=rt_cell_style_right) 
 
144
 
 
145
 
 
146
move_line_xls('report.move.line.list.xls', 
 
147
    'account.move.line',
 
148
    parser=move_line_list_print)
 
149
 
 
150
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
 
b'\\ No newline at end of file'