[FIX] procurement: remove yml statement that queries the db asynchronously
[odoo/odoo.git] / addons / mrp / report / mrp_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 osv import fields,osv
23
24
25 class report_workcenter_load(osv.osv):
26     _name="report.workcenter.load"
27     _description="Work Center Load"
28     _auto = False
29     _log_access = False
30     _columns = {
31         'name': fields.char('Week', size=64, required=True),
32         'workcenter_id': fields.many2one('mrp.workcenter', 'Work Center', required=True),
33         'cycle': fields.float('Nbr of cycle'),
34         'hour': fields.float('Nbr of hour'),
35     }
36
37     def init(self, cr):
38         cr.execute("""
39             create or replace view report_workcenter_load as (
40                 SELECT
41                     min(wl.id) as id,
42                     to_char(p.date_planned,'YYYY:mm:dd') as name,
43                     SUM(wl.hour) AS hour,
44                     SUM(wl.cycle) AS cycle,
45                     wl.workcenter_id as workcenter_id
46                 FROM
47                     mrp_production_workcenter_line wl
48                     LEFT JOIN mrp_production p
49                         ON p.id = wl.production_id
50                 GROUP BY
51                     wl.workcenter_id,
52                     to_char(p.date_planned,'YYYY:mm:dd')
53             )""")
54
55 report_workcenter_load()
56
57
58 class report_mrp_inout(osv.osv):
59     _name="report.mrp.inout"
60     _description="Stock value variation"
61     _auto = False
62     _log_access = False
63     _rec_name = 'date'
64     _columns = {
65         'date': fields.char('Week', size=64, required=True),
66         'value': fields.float('Stock value', required=True, digits=(16,2)),
67     }
68
69     def init(self, cr):
70         cr.execute("""
71             create or replace view report_mrp_inout as (
72                 select
73                     min(sm.id) as id,
74                     to_char(sm.date,'YYYY:IW') as date,
75                     sum(case when (sl.usage='internal') then
76                         pt.standard_price * sm.product_qty
77                     else
78                         0.0
79                     end - case when (sl2.usage='internal') then
80                         pt.standard_price * sm.product_qty
81                     else
82                         0.0
83                     end) as value
84                 from
85                     stock_move sm
86                 left join product_product pp
87                     on (pp.id = sm.product_id)
88                 left join product_template pt
89                     on (pt.id = pp.product_tmpl_id)
90                 left join stock_location sl
91                     on ( sl.id = sm.location_id)
92                 left join stock_location sl2
93                     on ( sl2.id = sm.location_dest_id)
94                 where
95                     sm.state in ('waiting','confirmed','assigned')
96                 group by
97                     to_char(sm.date,'YYYY:IW')
98             )""")
99
100 report_mrp_inout()
101
102
103 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
104