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 openerp.osv import fields,osv
23 from openerp import tools
24 import openerp.addons.decimal_precision as dp
26 class mrp_workorder(osv.osv):
27 _name = "mrp.workorder"
28 _description = "Work Order Report"
31 'nbr': fields.integer('# of Lines', readonly=True), # TDE FIXME master: rename into nbr_lines
32 'date': fields.date('Date', readonly=True),
33 'product_id': fields.many2one('product.product', 'Product', readonly=True),
34 'product_tmpl_id': fields.many2one('product.template', 'Product Template', readonly=True),
35 'category_id': fields.many2one('product.category', 'Product Category', readonly=True),
36 'product_qty': fields.float('Product Qty', digits_compute=dp.get_precision('Product Unit of Measure'), readonly=True),
37 'state': fields.selection([('draft','Draft'),('startworking', 'In Progress'),('pause','Pause'),('cancel','Cancelled'),('done','Finished')], 'Status', readonly=True),
38 'total_hours': fields.float('Total Hours', readonly=True),
39 'total_cycles': fields.float('Total Cycles', readonly=True),
40 'delay': fields.float('Delay', readonly=True),
41 'production_id': fields.many2one('mrp.production', 'Production', readonly=True),
42 'workcenter_id': fields.many2one('mrp.workcenter', 'Work Center', readonly=True),
43 'user_id': fields.many2one('res.users', 'Responsible'),
44 'routing_id': fields.many2one('mrp.routing', string='Routing', readonly=True),
45 'bom_id': fields.many2one('mrp.bom', 'Bill of Material', readonly=True),
49 tools.drop_view_if_exists(cr, 'mrp_workorder')
51 create or replace view mrp_workorder as (
53 date(wl.date_planned) as date,
55 mp.product_id as product_id,
57 t.categ_id as category_id,
58 sum(wl.hour) as total_hours,
59 avg(wl.delay) as delay,
60 (w.costs_hour*sum(wl.hour)) as total_cost,
61 wl.production_id as production_id,
62 wl.workcenter_id as workcenter_id,
63 sum(wl.cycle) as total_cycles,
65 sum(mp.product_qty) as product_qty,
70 from mrp_production_workcenter_line wl
71 left join mrp_workcenter w on (w.id = wl.workcenter_id)
72 left join mrp_production mp on (mp.id = wl.production_id)
73 left join product_product p on (mp.product_id=p.id)
74 left join product_template t on (p.product_tmpl_id=t.id)
76 w.costs_hour, mp.product_id, mp.name, mp.user_id, mp.routing_id, mp.bom_id, wl.state, wl.date_planned, wl.production_id, wl.workcenter_id, p.product_tmpl_id, t.categ_id
80 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: