[IMP] account, account_voucher: Improved the account voucher report.
[odoo/odoo.git] / addons / account_voucher / report / report_voucher.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 import time
23 from report import report_sxw
24 from tools import amount_to_text_en
25
26 class report_voucher(report_sxw.rml_parse):
27     def __init__(self, cr, uid, name, context):
28         super(report_voucher, self).__init__(cr, uid, name, context)
29         self.localcontext.update({
30             'time': time,
31             'convert':self.convert,
32             'debit':self.debit,
33             'credit':self.credit,
34             'get_ref' : self._get_ref
35         })
36
37     def convert(self, amount, cur):
38         amt_en = amount_to_text_en.amount_to_text(amount, 'en', cur);
39         return amt_en
40
41     def debit(self, move_ids):
42         debit = 0.0
43         for move in move_ids:
44             debit +=move.debit
45         return debit
46
47     def credit(self, move_ids):
48         credit = 0.0
49         for move in move_ids:
50             credit +=move.credit
51         return credit
52
53     def _get_ref(self, voucher_id, move_ids):
54         voucher_line = self.pool.get('account.voucher.line').search(self.cr, self.uid, [('partner_id','=',move_ids.partner_id.id), ('voucher_id','=',voucher_id)])
55         if voucher_line:
56             voucher = self.pool.get('account.voucher.line').browse(self.cr, self.uid, voucher_line)[0]
57             return voucher.ref
58         else:
59             return
60 report_sxw.report_sxw(
61     'report.voucher.cash_receipt.drcr',
62     'account.voucher',
63     'addons/account_voucher/report/report_voucher.rml',
64     parser=report_voucher,header="external"
65 )