[FIX] Schedule jobs even if their next time has passed.
[odoo/odoo.git] / addons / report_mrp / report_mrp.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution   
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
8 #    This program is free software: you can redistribute it and/or modify
9 #    it under the terms of the GNU General Public License as published by
10 #    the Free Software Foundation, either version 3 of the License, or
11 #    (at your option) any later version.
12 #
13 #    This program is distributed in the hope that it will be useful,
14 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #    GNU General Public License for more details.
17 #
18 #    You should have received a copy of the GNU General Public License
19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 ##############################################################################
22
23 from osv import fields,osv
24
25
26 class report_workcenter_load(osv.osv):
27     _name="report.workcenter.load"
28     _description="Workcenter Load"
29     _auto = False
30     _log_access = False
31     _columns = {
32         'name': fields.char('Week', size=64, required=True),
33         'workcenter_id': fields.many2one('mrp.workcenter', 'Workcenter', required=True),
34         'cycle': fields.float('Nbr of cycle'),
35         'hour': fields.float('Nbr of hour'),
36     }
37
38     def init(self, cr):
39         cr.execute("""
40             create or replace view report_workcenter_load as (
41                 SELECT
42                     min(wl.id) as id,
43                     to_char(p.date_planned,'YYYY:IW') as name,
44                     SUM(wl.hour) AS hour,
45                     SUM(wl.cycle) AS cycle,
46                     wl.workcenter_id as workcenter_id
47                 FROM
48                     mrp_production_workcenter_line wl
49                     LEFT JOIN mrp_production p
50                         ON p.id = wl.production_id
51                 GROUP BY
52                     wl.workcenter_id,
53                     to_char(p.date_planned,'YYYY:IW')
54             )""")
55
56 report_workcenter_load()
57
58
59 class report_mrp_inout(osv.osv):
60     _name="report.mrp.inout"
61     _description="Stock value variation"
62     _auto = False
63     _log_access = False
64     _rec_name = 'date'
65     _columns = {
66         'date': fields.char('Week', size=64, required=True),
67         'value': fields.float('Stock value', required=True, digits=(16,2)),
68     }
69
70     def init(self, cr):
71         cr.execute("""
72             create or replace view report_mrp_inout as (
73                 select
74                     min(sm.id) as id,
75                     to_char(sm.date_planned,'YYYY:IW') as date,
76                     sum(case when (sl.usage='internal') then
77                         pt.standard_price * sm.product_qty
78                     else
79                         0.0
80                     end - case when (sl2.usage='internal') then
81                         pt.standard_price * sm.product_qty
82                     else
83                         0.0
84                     end) as value
85                 from
86                     stock_move sm
87                 left join product_product pp
88                     on (pp.id = sm.product_id)
89                 left join product_template pt
90                     on (pt.id = pp.product_tmpl_id)
91                 left join stock_location sl
92                     on ( sl.id = sm.location_id)
93                 left join stock_location sl2
94                     on ( sl2.id = sm.location_dest_id)
95                 where
96                     sm.state in ('waiting','confirmed','assigned')
97                 group by
98                     to_char(sm.date_planned,'YYYY:IW')
99             )""")
100
101 report_mrp_inout()
102
103
104 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
105