[FIX] tools.convert: use tools.ustr() instead of str() on exceptions.
[odoo/odoo.git] / addons / account_asset / report / account_asset_report.py
1 # -*- encoding: 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 from openerp import tools
23 from openerp.osv import fields, osv
24
25 class asset_asset_report(osv.osv):
26     _name = "asset.asset.report"
27     _description = "Assets Analysis"
28     _auto = False
29     _columns = {
30         'name': fields.char('Year', size=16, required=False, readonly=True),
31         'purchase_date': fields.date('Purchase Date', readonly=True),
32         'depreciation_date': fields.date('Depreciation Date', readonly=True),
33         'asset_id': fields.many2one('account.asset.asset', string='Asset', readonly=True),
34         'asset_category_id': fields.many2one('account.asset.category',string='Asset category'),
35         'partner_id': fields.many2one('res.partner', 'Partner', readonly=True),
36         'state': fields.selection([('draft','Draft'),('open','Running'),('close','Close')], 'Status', readonly=True),
37         'depreciation_value': fields.float('Amount of Depreciation Lines', readonly=True),
38         'move_check': fields.boolean('Posted', readonly=True),
39         'nbr': fields.integer('# of Depreciation Lines', readonly=True),
40         'gross_value': fields.float('Gross Amount', readonly=True),
41         'posted_value': fields.float('Posted Amount', readonly=True),
42         'unposted_value': fields.float('Unposted Amount', readonly=True),
43         'company_id': fields.many2one('res.company', 'Company', readonly=True),
44     }
45     
46     def init(self, cr):
47         tools.drop_view_if_exists(cr, 'asset_asset_report')
48         cr.execute("""
49             create or replace view asset_asset_report as (
50                 select 
51                     min(dl.id) as id,
52                     dl.name as name,
53                     dl.depreciation_date as depreciation_date,
54                     a.purchase_date as purchase_date,
55                     (CASE WHEN (select min(d.id) from account_asset_depreciation_line as d
56                                 left join account_asset_asset as ac ON (ac.id=d.asset_id)
57                                 where a.id=ac.id) = min(dl.id)
58                       THEN a.purchase_value
59                       ELSE 0
60                       END) as gross_value,
61                     dl.amount as depreciation_value, 
62                     (CASE WHEN dl.move_check
63                       THEN dl.amount
64                       ELSE 0
65                       END) as posted_value,
66                     (CASE WHEN NOT dl.move_check
67                       THEN dl.amount
68                       ELSE 0
69                       END) as unposted_value,
70                     dl.asset_id as asset_id,
71                     dl.move_check as move_check,
72                     a.category_id as asset_category_id,
73                     a.partner_id as partner_id,
74                     a.state as state,
75                     count(dl.*) as nbr,
76                     a.company_id as company_id
77                 from account_asset_depreciation_line dl
78                     left join account_asset_asset a on (dl.asset_id=a.id)
79                 group by 
80                     dl.amount,dl.asset_id,dl.depreciation_date,dl.name,
81                     a.purchase_date, dl.move_check, a.state, a.category_id, a.partner_id, a.company_id,
82                     a.purchase_value, a.id, a.salvage_value
83         )""")
84         
85 asset_asset_report()
86
87 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: