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_report(self, cr, uid, ids, field_name=None, arg=None, context=None):
31
contract_obj = self.pool.get('financing.contract.contract')
32
# Context updated with wizard's value
33
reporting_type = self.read(cr, uid, ids, ['reporting_type'])[0]['reporting_type']
34
contract_id = self.read(cr, uid, ids, ['contract_id'])[0]['contract_id']
35
context.update({'reporting_type': reporting_type})
37
contract = contract_obj.browse(cr, uid, contract_id, context=context)
39
header_data = self._get_contract_header(cr, uid, contract, context=context)
40
footer_data = self._get_contract_footer(cr, uid, contract, context=context)
42
# Report lines with analytic lines for each one
43
analytic_data = [['Date',
55
contract_domain = contract_obj.get_contract_domain(cr,
58
reporting_type=reporting_type,
61
analytic_line_obj = self.pool.get('account.analytic.line')
62
analytic_lines = analytic_line_obj.search(cr, uid, contract_domain ,context=context)
64
amount_currency_sum = 0.0
66
for analytic_line in analytic_line_obj.browse(cr, uid, analytic_lines, context=context):
67
date_context = {'date': analytic_line.source_date or analytic_line.date,
68
'currency_table_id': contract.currency_table_id and contract.currency_table_id.id or None}
69
amount = self.pool.get('res.currency').compute(cr,
71
analytic_line.currency_id.id,
72
contract.reporting_currency.id,
73
analytic_line.amount_currency or 0.0,
76
amount_currency = analytic_line.amount_currency
78
amount_currency_sum += amount_currency
80
# Localized to add comma separators for thousands
81
formatted_amount = locale.format("%.2f", amount, grouping=True)
82
formatted_amount_currency = locale.format("%.2f", amount_currency, grouping=True)
84
analytic_data.append([analytic_line.date,
85
analytic_line.journal_id.name,
86
analytic_line.ref or '',
88
analytic_line.general_account_id.code + ' ' + analytic_line.general_account_id.name,
89
analytic_line.cost_center_id.name,
90
analytic_line.account_id.name,
92
contract.reporting_currency.name,
93
formatted_amount_currency,
94
analytic_line.currency_id.name,
95
analytic_line.invoice_line_id.name])
97
# Localized to add comma separators for thousands
98
formatted_amount_sum = locale.format("%.2f", amount_sum, grouping=True)
99
formatted_amount_currency_sum = locale.format("%.2f", amount_currency_sum, grouping=True)
101
analytic_data.append(['','','','','','','',formatted_amount_sum,'', formatted_amount_currency_sum])
103
data = header_data + [[]] + analytic_data + [[]] + footer_data
105
res[ids[0]] = self._create_csv(data)
109
'reporting_type': fields.selection([('project','Total project costs'),
110
('allocated','Funded costs')], 'Reporting type', required=True),
112
'data': fields.function(_get_report, method=True, store=False, string="CSV Report", type="binary", readonly="True"),
113
'filename': fields.char(size=128, string='Filename', required=True),
114
'contract_id': fields.many2one('financing.contract.contract', 'Contract', required=True),
117
wizard_expense_report()
119
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: