[MERGE]
[odoo/odoo.git] / addons / account_payment / report / payment_order.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
24 import pooler
25 from report import report_sxw
26
27 class payment_order(report_sxw.rml_parse):
28
29     def __init__(self, cr, uid, name, context=None):
30         super(payment_order, self).__init__(cr, uid, name, context=context)
31         self.localcontext.update( {
32             'time': time,
33             'get_invoice_name': self._get_invoice_name,
34             'get_company_currency': self._get_company_currency,
35             'get_company_currency_symbol': self._get_company_currency_symbol,
36             'get_amount_total_in_currency': self._get_amount_total_in_currency,
37             'get_amount_total': self._get_amount_total,
38             'get_account_name': self._get_account_name,
39         })
40
41     def _get_invoice_name(self, invoice_id):
42         if invoice_id:
43             pool = pooler.get_pool(self.cr.dbname)
44             value_name = pool.get('account.invoice').name_get(self.cr, self.uid, [invoice_id])
45             if value_name:
46                 return value_name[0][1]
47         return False
48
49     def _get_amount_total_in_currency(self, payment):
50         total = 0.0
51         if payment.line_ids:
52             currency_cmp = payment.line_ids[0].currency.id
53         else:
54             return False
55         for line in payment.line_ids:
56             if currency_cmp == line.currency.id:
57                 total += line.amount_currency
58             else:
59                 return False
60         return total
61
62     def _get_amount_total(self, payment):
63         total = 0.0
64         if not payment.line_ids:
65             return False
66         for line in payment.line_ids:
67             total += line.amount
68         return total
69
70     def _get_company_currency(self):
71         pool = pooler.get_pool(self.cr.dbname)
72         user = pool.get('res.users').browse(self.cr, self.uid, self.uid)
73         return user.company_id and user.company_id.currency_id and user.company_id.currency_id.symbol or False
74
75     def _get_company_currency_symbol(self):
76         pool = pooler.get_pool(self.cr.dbname)
77         user = pool.get('res.users').browse(self.cr, self.uid, self.uid)
78         return user.company_id and user.company_id.currency_id and user.company_id.currency_id.symbol or False
79
80     def _get_account_name(self,bank_id):
81         if bank_id:
82             pool = pooler.get_pool(self.cr.dbname)
83             value_name = pool.get('res.partner.bank').name_get(self.cr, self.uid, [bank_id])
84             if value_name:
85                 return value_name[0][1]
86         return False
87
88 report_sxw.report_sxw('report.payment.order', 'payment.order', 'addons/account_payment/report/payment_order.rml', parser=payment_order, header="external")
89
90 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: