[FIX] Removed all code and XML mentions of "finnished", as it's written "finished...
[odoo/odoo.git] / addons / mrp / report / mrp_production_order.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 import tools
24
25
26 class mrp_production_order(osv.osv):
27     _name = "mrp.production.order"
28     _description = "Production Order Report"
29     _auto = False
30     _columns = {
31         'year': fields.char('Year',size=64,readonly=True),
32         'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
33                                   ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
34         'day': fields.char('Day',size=64,readonly=True),
35         'origin': fields.char('Source Document', size=64),
36         'nbr': fields.integer('# of Lines', readonly=True),
37         'products_to_consume': fields.integer('Products to Consume', readonly=True),
38         'consumed_products': fields.integer('Consumed Products', readonly=True),
39         'date': fields.date('Date', readonly=True),
40         'product_id': fields.many2one('product.product', 'Product', readonly=True),
41         'product_id2': fields.many2one('product.product', 'Product Consumed', readonly=True),
42         'product_qty': fields.float('Product Qty', readonly=True),
43         'state': fields.selection([('draft','Draft'),
44                                    ('picking_except', 'Picking Exception'),
45                                    ('confirmed','Waiting Goods'),
46                                    ('ready','Ready to Produce'),
47                                    ('in_production','In Production'),
48                                    ('cancel','Cancelled'),
49                                    ('done','Done')],
50                                     'State', readonly=True),
51         'date_planned':fields.date('Scheduled Date'),
52         'location_src_id': fields.many2one('stock.location', 'Raw Materials Location', readonly=True),
53         'date_start': fields.datetime('Start Date',readonly=True),
54         'date_finished': fields.datetime('End Date',readonly=True),
55         'location_dest_id': fields.many2one('stock.location', 'Finished Products Location', readonly=True),
56         'company_id': fields.many2one('res.company','Company',readonly=True),
57         'bom_id': fields.many2one('mrp.bom', 'Bill of Material',readonly=True),
58         'routing_id': fields.many2one('mrp.routing', string='Routing',readonly=True),
59         'picking_id': fields.many2one('stock.picking', 'Picking list', readonly=True),
60         'product_uom': fields.many2one('product.uom', 'Product UOM', readonly=True),
61         'priority': fields.selection([('0','Not urgent'),
62                                       ('1','Normal'),
63                                       ('2','Urgent'),
64                                       ('3','Very Urgent')],
65                                        'Priority',readonly=True),
66
67
68     }
69     def init(self, cr):
70         tools.drop_view_if_exists(cr, 'mrp_production_order')
71         cr.execute("""
72             create or replace view mrp_production_order as (
73                 select
74                      min(l.id) as id,
75                      to_date(to_char(s.create_date, 'MM-dd-YYYY'),'MM-dd-YYYY') as date,
76                      to_char(s.create_date, 'YYYY') as year,
77                      to_char(s.create_date, 'MM') as month,
78                      to_char(s.create_date, 'YYYY-MM-DD') as day,
79                      s.product_id as product_id,
80                      l.product_id as product_id2,
81                      l.product_uom,
82                      sum(l.product_qty * u.factor) as product_qty,
83                      s.company_id as company_id,
84                      (select 1) as nbr,
85                      (select sum(sm.product_qty) from stock_move as sm
86                         left join mrp_production_move_ids as mv on (sm.id=mv.move_id)
87                         left join mrp_production_product_line as ll on (ll.production_id=mv.production_id)
88                         where sm.product_id=ll.product_id and ll.id=l.id
89                         and sm.state not in ('done','cancel')
90                         group by sm.product_id) as products_to_consume,
91                     (select sum(sm.product_qty)/2 from stock_move as sm
92                         left join mrp_production_move_ids as mv on (sm.id=mv.move_id)
93                         left join mrp_production_product_line as ll on (ll.production_id=mv.production_id)
94                         where sm.product_id=ll.product_id and ll.id=l.id
95                         and sm.state in ('done','cancel')
96                         group by sm.product_id) as consumed_products,
97                      s.location_src_id,
98                      s.location_dest_id,
99                      s.bom_id,
100                      s.routing_id,
101                      s.picking_id,
102                      s.date_start,
103                      s.date_finished,
104                      to_date(to_char(s.date_planned, 'dd-MM-YYYY'),'dd-MM-YYYY') as date_planned,
105                      s.origin,
106                      s.priority,
107                      s.state
108                  from mrp_production_product_line l
109                  left join mrp_production s on (s.id=l.production_id)
110                  left join product_uom u on (u.id=l.product_uom)
111                  group by
112                      to_char(s.create_date, 'YYYY'),
113                      to_char(s.create_date, 'MM'),
114                      to_char(s.create_date, 'YYYY-MM-DD'),
115                      to_date(to_char(s.create_date, 'MM-dd-YYYY'),'MM-dd-YYYY'),
116                      l.product_id,
117                      s.product_id,
118                      l.product_uom,
119                      s.id,
120                      l.id,
121                      s.bom_id,
122                      s.routing_id,
123                      s.picking_id,
124                      s.priority,
125                      s.location_src_id,
126                      s.location_dest_id,
127                      s.state,
128                      to_date(to_char(s.date_planned, 'dd-MM-YYYY'),'dd-MM-YYYY'),
129                      s.origin,
130                      s.date_start,
131                      s.date_finished,
132                      s.company_id
133             )""")
134 mrp_production_order()
135 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
136