Launchpad automatic translations update.
[odoo/odoo.git] / addons / account / report / account_analytic_entries_report.py
1 # -*- coding: 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 analytic_entries_report(osv.osv):
26     _name = "analytic.entries.report"
27     _description = "Analytic Entries Statistics"
28     _auto = False
29     _columns = {
30         'date': fields.date('Date', readonly=True),
31         'year': fields.char('Year', size=4, readonly=True),
32         'day': fields.char('Day', size=128, readonly=True),
33         'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'),
34             ('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'),
35             ('10','October'), ('11','November'), ('12','December')], 'Month',readonly=True),
36         'user_id': fields.many2one('res.users', 'User',readonly=True),
37         'name': fields.char('Description', size=64, readonly=True),
38         'partner_id': fields.many2one('res.partner', 'Partner'),
39         'company_id': fields.many2one('res.company', 'Company', required=True),
40         'currency_id': fields.many2one('res.currency', 'Currency', required=True),
41         'account_id': fields.many2one('account.analytic.account', 'Account', required=False),
42         'general_account_id': fields.many2one('account.account', 'General Account', required=True),
43         'journal_id': fields.many2one('account.analytic.journal', 'Journal', required=True),
44         'move_id': fields.many2one('account.move.line', 'Move', required=True),
45         'product_id': fields.many2one('product.product', 'Product', required=True),
46         'product_uom_id': fields.many2one('product.uom', 'Product Unit of Measure', required=True),
47         'amount': fields.float('Amount', readonly=True),
48         'unit_amount': fields.float('Quantity', readonly=True),
49         'nbr': fields.integer('#Entries', readonly=True),
50     }
51     def init(self, cr):
52         tools.drop_view_if_exists(cr, 'analytic_entries_report')
53         cr.execute("""
54             create or replace view analytic_entries_report as (
55                  select
56                      min(a.id) as id,
57                      count(distinct a.id) as nbr,
58                      a.date as date,
59                      to_char(a.date, 'YYYY') as year,
60                      to_char(a.date, 'MM') as month,
61                      to_char(a.date, 'YYYY-MM-DD') as day,
62                      a.user_id as user_id,
63                      a.name as name,
64                      analytic.partner_id as partner_id,
65                      a.company_id as company_id,
66                      a.currency_id as currency_id,
67                      a.account_id as account_id,
68                      a.general_account_id as general_account_id,
69                      a.journal_id as journal_id,
70                      a.move_id as move_id,
71                      a.product_id as product_id,
72                      a.product_uom_id as product_uom_id,
73                      sum(a.amount) as amount,
74                      sum(a.unit_amount) as unit_amount
75                  from
76                      account_analytic_line a, account_analytic_account analytic
77                  where analytic.id = a.account_id
78                  group by
79                      a.date, a.user_id,a.name,analytic.partner_id,a.company_id,a.currency_id,
80                      a.account_id,a.general_account_id,a.journal_id,
81                      a.move_id,a.product_id,a.product_uom_id
82             )
83         """)
84 analytic_entries_report()
85
86 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: