[FIX] Change the year of the copyright
[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
27 class report_voucher(report_sxw.rml_parse):
28     def __init__(self, cr, uid, name, context):
29         super(report_voucher, self).__init__(cr, uid, name, context)
30         self.localcontext.update({
31             'time': time,
32             'convert':self.convert,
33             'debit':self.debit,
34             'credit':self.credit,
35             'get_ref' : self._get_ref
36         })
37
38     def convert(self,amount, cur):
39         amt_en = amount_to_text_en.amount_to_text(amount,'en',cur);
40         return amt_en
41     
42     def debit(self, move_ids):
43         debit = 0.0
44         for move in move_ids:#self.pool.get('account.move.line').browse(self.cr, self.uid, move_ids):
45             debit +=move.debit
46         return debit
47     
48     def credit(self, move_ids):
49         credit = 0.0
50         for move in move_ids:#self.pool.get('account.move.line').browse(self.cr, self.uid, move_ids):
51             credit +=move.credit
52         return credit
53     
54     def _get_ref(self, voucher_id, move_ids):
55         voucher_line = self.pool.get('account.voucher.line').search(self.cr, self.uid, [('partner_id','=',move_ids.partner_id.id), ('voucher_id','=',voucher_id)])
56         if voucher_line:
57             voucher = self.pool.get('account.voucher.line').browse(self.cr, self.uid, voucher_line)[0]
58             return voucher.ref
59         else:
60             return
61 report_sxw.report_sxw(
62     'report.voucher.cash_receipt.drcr',
63     'account.voucher',
64     'addons/account_voucher/report/report_voucher.rml',
65     parser=report_voucher,header=False
66 )