[IMP] Use the openerp namespace in YML tests.
[odoo/odoo.git] / addons / account_voucher / report / account_voucher_print.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 openerp.report import report_sxw
24 from openerp.tools import amount_to_text_en
25
26 class report_voucher_print(report_sxw.rml_parse):
27     def __init__(self, cr, uid, name, context):
28         super(report_voucher_print, self).__init__(cr, uid, name, context)
29         self.localcontext.update({
30             'time': time,
31             'get_title': self.get_title,
32             'get_lines':self.get_lines,
33             'get_on_account':self.get_on_account,
34             'convert':self.convert
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 get_lines(self, voucher):
42         result = []
43         if voucher.type in ('payment','receipt'):
44             type = voucher.line_ids and voucher.line_ids[0].type or False
45             for move in voucher.move_ids:
46                 res = {}
47                 amount = move.credit
48                 if type == 'dr':
49                     amount = move.debit
50                 if amount > 0.0:
51                     res['pname'] = move.partner_id.name
52                     res['ref'] = 'Agst Ref'+" "+str(move.name)
53                     res['aname'] = move.account_id.name
54                     res['amount'] = amount
55                     result.append(res)
56         else:
57             type = voucher.line_ids and voucher.line_ids[0].type or False
58             for move in voucher.move_ids:
59                 res = {}
60                 amount = move.credit
61                 if type == 'dr':
62                     amount = move.debit
63                 if amount > 0.0:
64                     res['pname'] = move.partner_id.name
65                     res['ref'] =  move.name
66                     res['aname'] = move.account_id.name
67                     res['amount'] = amount
68                     result.append(res)
69         return result
70
71     def get_title(self, type):
72         title = ''
73         if type:
74             title = type[0].swapcase() + type[1:] + " Voucher"
75         return title
76
77     def get_on_account(self, voucher):
78         name = ""
79         if voucher.type == 'receipt':
80             name = "Received cash from "+str(voucher.partner_id.name)
81         elif voucher.type == 'payment':
82             name = "Payment from "+str(voucher.partner_id.name)
83         elif voucher.type == 'sale':
84             name = "Sale to "+str(voucher.partner_id.name)
85         elif voucher.type == 'purchase':
86             name = "Purchase from "+str(voucher.partner_id.name)
87         return name
88
89 report_sxw.report_sxw(
90     'report.voucher.print',
91     'account.voucher',
92     'addons/account_voucher/report/account_voucher_print.rml',
93     parser=report_voucher_print,header="external"
94 )
95
96 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: