[REf] account_* clean
[odoo/odoo.git] / addons / account_voucher / report / account_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             'get_title': self.get_title,
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 get_title(self, type):
43         title = ''
44         if type:
45             title = type[0].swapcase() + type[1:] + " Voucher"
46         return title
47
48     def debit(self, move_ids):
49         debit = 0.0
50         for move in move_ids:
51             debit += move.debit
52         return debit
53
54     def credit(self, move_ids):
55         credit = 0.0
56         for move in move_ids:
57             credit += move.credit
58         return credit
59
60     def _get_ref(self, voucher_id, move_ids):
61         voucher_line = self.pool.get('account.voucher.line').search(self.cr, self.uid, [('partner_id', '=', move_ids.partner_id.id), ('voucher_id', '=', voucher_id)])
62         if voucher_line:
63             voucher = self.pool.get('account.voucher.line').browse(self.cr, self.uid, voucher_line)[0]
64             return voucher.name
65         else:
66             return
67 report_sxw.report_sxw(
68     'report.voucher.cash_receipt.drcr',
69     'account.voucher',
70     'addons/account_voucher/report/account_voucher.rml',
71     parser=report_voucher,header="external"
72 )