~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to financing_contract/wizard/wizard_expense_report.py

  • Committer: jf
  • Date: 2011-12-30 09:08:24 UTC
  • mfrom: (395.8.8 UF-661)
  • Revision ID: jf@tempo4-20111230090824-4zbrgeyqqu4z4so3
UF-661 [MERGE] Financing contracts: Export CSV File

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2011 MSF, TeMPO Consulting.
 
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
from osv import fields, osv
 
22
import locale
 
23
 
 
24
class wizard_expense_report(osv.osv_memory):
 
25
    
 
26
    _name = "wizard.expense.report"
 
27
    _inherit = "wizard.csv.report"
 
28
        
 
29
    def _get_expenses_data(self, cr, uid, contract_id, reporting_type, context=None):
 
30
        res = {}
 
31
        contract_obj = self.pool.get('financing.contract.contract')
 
32
        # Context updated with wizard's value
 
33
        context.update({'reporting_type': reporting_type})
 
34
        
 
35
        contract = contract_obj.browse(cr, uid, contract_id, context=context)
 
36
        
 
37
        header_data = self._get_contract_header(cr, uid, contract, context=context)
 
38
        footer_data = self._get_contract_footer(cr, uid, contract, context=context)
 
39
        
 
40
        # Report lines with analytic lines for each one
 
41
        analytic_data = [['Date',
 
42
                          'Analytic Journal',
 
43
                          'Reference',
 
44
                          'Description',
 
45
                          'General Account',
 
46
                          'Cost Center',
 
47
                          'Funding Pool',
 
48
                          'Booking Amount',
 
49
                          'Booking Currency',
 
50
                          'Reporting Amount',
 
51
                          'Reporting Currency',
 
52
                          'Invoice Line']]
 
53
        contract_domain = contract_obj.get_contract_domain(cr,
 
54
                                                           uid,
 
55
                                                           contract,
 
56
                                                           reporting_type=reporting_type,
 
57
                                                           context=context)
 
58
        # get lines
 
59
        analytic_line_obj = self.pool.get('account.analytic.line')
 
60
        analytic_lines = analytic_line_obj.search(cr, uid, contract_domain ,context=context)
 
61
        amount_sum = 0.0
 
62
        amount_currency_sum = 0.0
 
63
        currency_table = None
 
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,
 
68
                                                           uid,
 
69
                                                           analytic_line.currency_id.id,
 
70
                                                           contract.reporting_currency.id, 
 
71
                                                           analytic_line.amount_currency or 0.0,
 
72
                                                           round=True,
 
73
                                                           context=date_context)
 
74
            amount_currency = analytic_line.amount_currency
 
75
            amount_sum += amount
 
76
            amount_currency_sum += amount_currency
 
77
            
 
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)
 
81
            
 
82
            analytic_data.append([analytic_line.date,
 
83
                                  analytic_line.journal_id.name,
 
84
                                  analytic_line.ref or '',
 
85
                                  analytic_line.name,
 
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,
 
89
                                  formatted_amount,
 
90
                                  contract.reporting_currency.name,
 
91
                                  formatted_amount_currency,
 
92
                                  analytic_line.currency_id.name,
 
93
                                  analytic_line.invoice_line_id.name])
 
94
            
 
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)
 
98
        
 
99
        analytic_data.append(['','','','','','','',formatted_amount_sum,'', formatted_amount_currency_sum])
 
100
        
 
101
        data = header_data + [[]] + analytic_data + [[]] + footer_data
 
102
        
 
103
        return data
 
104
    
 
105
wizard_expense_report()
 
106
 
 
107
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: