[IMP]
[odoo/odoo.git] / addons / account_voucher / report / report_voucher.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution   
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
8 #    This program is free software: you can redistribute it and/or modify
9 #    it under the terms of the GNU General Public License as published by
10 #    the Free Software Foundation, either version 3 of the License, or
11 #    (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 General Public License for more details.
17 #
18 #    You should have received a copy of the GNU General Public License
19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 ##############################################################################
22
23 import time
24 from report import report_sxw
25 from tools import amount_to_text_en
26
27
28 class report_voucher(report_sxw.rml_parse):
29     def __init__(self, cr, uid, name, context):
30         super(report_voucher, self).__init__(cr, uid, name, context)
31         self.localcontext.update({
32             'time': time,
33             'convert':self.convert,
34             'debit':self.debit,
35             'credit':self.credit,
36             'get_ref' : self._get_ref
37         })
38
39     def convert(self,amount, cur):
40         amt_en = amount_to_text_en.amount_to_text(amount,'en',cur);
41         return amt_en
42     
43     def debit(self, move_ids):
44         debit = 0.0
45         for move in move_ids:#self.pool.get('account.move.line').browse(self.cr, self.uid, move_ids):
46             debit +=move.debit
47         return debit
48     
49     def credit(self, move_ids):
50         credit = 0.0
51         for move in move_ids:#self.pool.get('account.move.line').browse(self.cr, self.uid, move_ids):
52             credit +=move.credit
53         return credit
54     
55     def _get_ref(self, voucher_id, move_ids):
56         voucher_line = self.pool.get('account.voucher.line').search(self.cr, self.uid, [('partner_id','=',move_ids.partner_id.id), ('voucher_id','=',voucher_id)])
57         if voucher_line:
58             voucher = self.pool.get('account.voucher.line').browse(self.cr, self.uid, voucher_line)[0]
59             return voucher.ref
60         else:
61             return
62 report_sxw.report_sxw(
63     'report.voucher.cash_receipt',
64     'account.voucher',
65     'addons/account_voucher/report/report_voucher.rml',
66     parser=report_voucher,header=False
67 )
68
69 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: