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_qty': fields.float('Product Qty', digits_compute=dp.get_precision('Product Unit of Measure'), readonly=True),
35 'state': fields.selection([('draft','Draft'),('startworking', 'In Progress'),('pause','Pause'),('cancel','Cancelled'),('done','Finished')], 'Status', readonly=True),
36 'total_hours': fields.float('Total Hours', readonly=True),
37 'total_cycles': fields.float('Total Cycles', readonly=True),
38 'delay': fields.float('Delay', readonly=True),
39 'production_id': fields.many2one('mrp.production', 'Production', readonly=True),
40 'workcenter_id': fields.many2one('mrp.workcenter', 'Work Center', readonly=True)
44 tools.drop_view_if_exists(cr, 'mrp_workorder')
46 create or replace view mrp_workorder as (
48 date(wl.date_planned) as date,
50 mp.product_id as product_id,
51 sum(wl.hour) as total_hours,
52 avg(wl.delay) as delay,
53 (w.costs_hour*sum(wl.hour)) as total_cost,
54 wl.production_id as production_id,
55 wl.workcenter_id as workcenter_id,
56 sum(wl.cycle) as total_cycles,
58 sum(mp.product_qty) as product_qty,
60 from mrp_production_workcenter_line wl
61 left join mrp_workcenter w on (w.id = wl.workcenter_id)
62 left join mrp_production mp on (mp.id = wl.production_id)
64 w.costs_hour, mp.product_id, mp.name, wl.state, wl.date_planned, wl.production_id, wl.workcenter_id
68 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: