1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 MSF, TeMPO Consulting.
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.
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.
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/>.
20
##############################################################################
21
from osv import fields, osv
24
class wizard_expense_report(osv.osv_memory):
26
_name = "wizard.expense.report"
27
_inherit = "wizard.csv.report"
29
def _get_expenses_data(self, cr, uid, contract_id, reporting_type, context=None):
31
contract_obj = self.pool.get('financing.contract.contract')
32
# Context updated with wizard's value
33
context.update({'reporting_type': reporting_type})
35
contract = contract_obj.browse(cr, uid, contract_id, context=context)
37
header_data = self._get_contract_header(cr, uid, contract, context=context)
38
footer_data = self._get_contract_footer(cr, uid, contract, context=context)
40
# Report lines with analytic lines for each one
41
analytic_data = [['Date',
53
contract_domain = contract_obj.get_contract_domain(cr,
56
reporting_type=reporting_type,
59
analytic_line_obj = self.pool.get('account.analytic.line')
60
analytic_lines = analytic_line_obj.search(cr, uid, contract_domain ,context=context)
62
amount_currency_sum = 0.0
64
for analytic_line in analytic_line_obj.browse(cr, uid, analytic_lines, context=context):
65
date_context = {'date': analytic_line.source_date or analytic_line.date,
66
'currency_table_id': contract.currency_table_id and contract.currency_table_id.id or None}
67
amount = self.pool.get('res.currency').compute(cr,
69
analytic_line.currency_id.id,
70
contract.reporting_currency.id,
71
analytic_line.amount_currency or 0.0,
74
amount_currency = analytic_line.amount_currency
76
amount_currency_sum += amount_currency
78
# Localized to add comma separators for thousands
79
formatted_amount = locale.format("%.2f", amount, grouping=True)
80
formatted_amount_currency = locale.format("%.2f", amount_currency, grouping=True)
82
analytic_data.append([analytic_line.date,
83
analytic_line.journal_id.name,
84
analytic_line.ref or '',
86
analytic_line.general_account_id.code + ' ' + analytic_line.general_account_id.name,
87
analytic_line.cost_center_id.name,
88
analytic_line.account_id.name,
90
contract.reporting_currency.name,
91
formatted_amount_currency,
92
analytic_line.currency_id.name,
93
analytic_line.invoice_line_id.name])
95
# Localized to add comma separators for thousands
96
formatted_amount_sum = locale.format("%.2f", amount_sum, grouping=True)
97
formatted_amount_currency_sum = locale.format("%.2f", amount_currency_sum, grouping=True)
99
analytic_data.append(['','','','','','','',formatted_amount_sum,'', formatted_amount_currency_sum])
101
data = header_data + [[]] + analytic_data + [[]] + footer_data
105
wizard_expense_report()
107
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: