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
26 class mrp_production_order(osv.osv):
27 _name = "mrp.production.order"
28 _description = "Production Order Report"
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'),
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'),
65 'Priority',readonly=True),
70 tools.drop_view_if_exists(cr, 'mrp_production_order')
72 create or replace view mrp_production_order as (
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,
82 sum(l.product_qty * u.factor) as product_qty,
83 s.company_id as company_id,
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,
104 to_date(to_char(s.date_planned, 'dd-MM-YYYY'),'dd-MM-YYYY') as date_planned,
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)
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'),
128 to_date(to_char(s.date_planned, 'dd-MM-YYYY'),'dd-MM-YYYY'),
134 mrp_production_order()
135 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: