1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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
##############################################################################
22
from osv import fields,osv
25
class report_account_analytic_resource_usage(osv.osv):
26
_name = "report.account.analytic.resource.usage"
27
_description = "Resource Usage Analysis"
30
'date': fields.date('Date', readonly=True),
31
'day': fields.char('Day', size=128, readonly=True),
32
'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')], 'Month', readonly=True),
33
'year': fields.char('Year', size=64, required=False, readonly=True),
34
'period_id': fields.many2one('account.period', 'Period', readonly=True),
35
'account_id': fields.many2one('account.analytic.account', 'Analytic Account', readonly=True),
36
'product_id': fields.many2one('product.product', 'Product', readonly=True),
37
'product_uom_id': fields.many2one('product.uom', 'UoM', readonly=True),
38
'user_id': fields.many2one('res.users', 'User', readonly=True),
39
'amount_plan': fields.float('Planned Amount', readonly=True, help='Calculated by multiplying the quantity and the price given in the Product\'s cost price. Always expressed in the company main currency.'),
40
'amount_commit': fields.float('Commited Amount', readonly=True, help='Calculated by multiplying the quantity and the price given in the Product\'s cost price. Always expressed in the company main currency.'),
41
'unit_amount_plan': fields.float('Planned Quantity', help='Specifies the amount of quantity to count.'),
42
'unit_amount_commit': fields.float('Commited Quantity', help='Specifies the amount of quantity to count.'),
43
'amount_real': fields.float('Real Amount', readonly=True, help='Calculated by multiplying the quantity and the price given in the Product\'s cost price. Always expressed in the company main currency.'),
44
'unit_amount_real': fields.float('Real Quantity', readonly=True, help='Specifies the amount of quantity to count.'),
51
@param cr: the current row, from the database cursor,
53
tools.drop_view_if_exists(cr, 'report_account_analytic_resource_usage')
56
create or replace view report_account_analytic_resource_usage as (
59
ROW_NUMBER() over (order by tot.date) as id,
61
to_char(tot.date, 'YYYY') as year,
62
to_char(tot.date, 'MM') as month,
63
to_char(tot.date, 'YYYY-MM-DD') as day,
64
sum(tot.unit_amount_real) as unit_amount_real,
65
sum(tot.unit_amount_plan) as unit_amount_plan,
66
sum(tot.unit_amount_commit) as unit_amount_commit,
67
sum(tot.amount_real) as amount_real,
68
sum(tot.amount_plan) as amount_plan,
69
sum(tot.amount_commit) as amount_commit,
77
CAST( unit_amount AS FLOAT) AS unit_amount_real,
78
CAST( 0 AS FLOAT) AS unit_amount_plan,
79
CAST( 0 AS FLOAT) AS unit_amount_commit,
80
CAST( amount AS FLOAT) AS amount_real,
81
CAST( 0 AS FLOAT) AS amount_plan,
82
CAST( 0 AS FLOAT) AS amount_commit,
89
FROM account_analytic_line
93
CAST( 0 AS FLOAT) AS unit_amount_real,
94
CAST( unit_amount AS FLOAT) AS unit_amount_plan,
95
CAST( 0 AS FLOAT) AS unit_amount_commit,
96
CAST( 0 AS FLOAT) AS amount_real,
97
CAST( amount AS FLOAT) AS amount_plan,
98
CAST( 0 AS FLOAT) AS amount_commit,
105
FROM account_analytic_line_plan
108
CAST( 0 AS FLOAT) AS unit_amount_real,
109
CAST( 0 AS FLOAT) AS unit_amount_plan,
110
CAST( unit_amount AS FLOAT) AS unit_amount_commit,
111
CAST( 0 AS FLOAT) AS amount_real,
112
CAST( 0 AS FLOAT) AS amount_plan,
113
CAST( amount AS FLOAT) AS amount_commit,
120
FROM account_analytic_line_commit
135
report_account_analytic_resource_usage()