Tab to Space
[odoo/odoo.git] / addons / project_mrp / mrp.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 # Copyright (c) 2005 TINY SPRL. (http://tiny.be) All Rights Reserved.
5 #
6 # $Id: project.py 1011 2005-07-26 08:11:45Z nicoe $
7 #
8 # WARNING: This program as such is intended to be used by professional
9 # programmers who take the whole responsability of assessing all potential
10 # consequences resulting from its eventual inadequacies and bugs
11 # End users who are looking for a ready-to-use solution with commercial
12 # garantees and support are strongly adviced to contract a Free Software
13 # Service Company
14 #
15 # This program is Free Software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License
17 # as published by the Free Software Foundation; either version 2
18 # of the License, or (at your option) any later version.
19 #
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28 #
29 ##############################################################################
30
31 from osv import fields, osv, orm
32
33 class mrp_procurement(osv.osv):
34     _name = "mrp.procurement"
35     _inherit = "mrp.procurement"
36     
37     def action_produce_assign_service(self, cr, uid, ids, context={}):
38         for procurement in self.browse(cr, uid, ids):
39             sline = self.pool.get('sale.order.line')
40             sale_ids = sline.search(cr, uid, [('procurement_id','=',procurement.id)], context)
41             content = ''
42             l = None
43             for line in sline.browse(cr, uid, sale_ids, context=context):
44                 content += (line.notes or '')
45                 l = line
46
47             self.write(cr, uid, [procurement.id], {'state':'running'})
48             task_id = self.pool.get('project.task').create(cr, uid, {
49                 'name': procurement.origin+': '+procurement.name,
50                 'date_deadline': procurement.date_planned,
51                 'planned_hours': procurement.product_qty,
52                 'remaining_hours': procurement.product_qty,
53                 'user_id': procurement.product_id.product_manager.id,
54                 'notes': l and l.order_id.note or '',
55                 'procurement_id': procurement.id,
56                 'description': content,
57                 'date_deadline': procurement.date_planned,
58                 'state': 'draft',
59                 'partner_id': l and l.order_id.partner_id.id or False
60             })
61         return task_id
62 mrp_procurement()
63
64 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
65