[MERGE]
[odoo/odoo.git] / addons / account / report / account_tax_code.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 ##############################################################################
4 #
5 #    OpenERP, Open Source Management Solution
6 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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 time
24 import rml_parse
25 from report import report_sxw
26 import re
27
28 def _get_country(record):
29     if record.partner_id \
30             and record.partner_id.address \
31             and record.partner_id.address[0].country_id:
32         return record.partner_id.address[0].country_id.code
33     else:
34         return ''
35
36 def _record_to_report_line(record):
37     return {'date': record.date,
38             'ref': record.ref,
39             'acode': record.account_id.code,
40             'name': record.name,
41             'debit': record.debit,
42             'credit': record.credit,
43             'pname': record.partner_id and record.partner_id.name or '',
44             'country': _get_country(record)
45             }
46
47 class account_tax_code_report(rml_parse.rml_parse):
48     def __init__(self, cr, uid, name, context):
49         super(account_tax_code_report, self).__init__(cr, uid, name, context=context)
50         self.localcontext.update({
51             'time': time,
52             'get_line':self.get_line,
53         })
54
55     def get_line(self, obj):
56         line_ids = self.pool.get('account.move.line').search(self.cr, self.uid, [('tax_code_id','=',obj.id)])
57         if not line_ids: return []
58
59         return map(_record_to_report_line,
60                    self.pool.get('account.move.line')\
61                        .browse(self.cr, self.uid, line_ids))
62
63 report_sxw.report_sxw('report.account.tax.code.entries', 'account.tax.code',
64     'addons/account/report/account_tax_code.rml', parser=account_tax_code_report, header="internal")
65
66 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: