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, orm
26 class procurement_order(osv.osv):
27 _name = "procurement.order"
28 _inherit = "procurement.order"
30 'task_id': fields.many2one('project.task', 'Task')
33 def action_produce_assign_service(self, cr, uid, ids, context=None):
36 for procurement in self.browse(cr, uid, ids):
37 sline = self.pool.get('sale.order.line')
38 product_obj=self.pool.get('product.product')
40 sale_order = self.pool.get('sale.order')
41 so_ref = procurement.name.split(':')[0]
42 order_ids = sale_order.search(cr, uid, [('name', '=', so_ref)], context)
45 sale_ids = sale_order.read(cr, uid, order_ids[0], ['order_line'], context=context)['order_line']
47 so_ref = procurement.origin.split(':')[0]
48 sale_ids = sline.search(cr, uid, [('procurement_id', '=',procurement.id)], context)
51 analytic_account_id = False
54 for line in sline.browse(cr, uid, sale_ids, context=context):
55 content += (line.notes or '')
57 partner_id = line.order_id.partner_id.id
58 if line.order_id.project_id:
59 analytic_account_id = line.order_id.project_id.id
60 partner_id = line.order_id.partner_id.id
61 content+="\n\n"+line.order_id.project_id.complete_name
64 # Creating a project for task.Project is created from Procurement.
65 project_obj = self.pool.get('project.project')
66 proj_name = tools.ustr(so_ref)
67 product_project_id =procurement.product_id.project_id and procurement.product_id.project_id.id or False
68 proj_exist_id = project_obj.search(cr, uid, [('name', '=', proj_name)], context=context)
70 project_id = project_obj.create(cr, uid, {'name': proj_name, 'partner_id': partner_id,'parent_id':product_project_id})
72 project_id = proj_exist_id[0]
74 self.write(cr, uid, [procurement.id], {'state': 'running'})
78 if procurement.product_id.type == 'service':
79 proc_name = procurement.name
80 if procurement.origin == proc_name:
81 proc_name = procurement.product_id.name
83 name_task = (procurement.origin, proc_name or '')
85 name_task = (procurement.product_id.name or procurement.origin, procurement.name or '')
86 planned_hours= procurement.product_id.sale_delay +procurement.product_id. produce_delay
87 task_id = self.pool.get('project.task').create(cr, uid, {
88 'name': '%s:%s' % name_task,
89 'date_deadline': procurement.date_planned,
90 'planned_hours':planned_hours,
91 'remaining_hours': planned_hours,
92 'user_id': procurement.product_id.product_manager.id,
93 'notes': "b"+(l and l.order_id.note or ''),
94 'procurement_id': procurement.id,
95 'description': content,
96 'date_deadline': procurement.date_planned,
98 'partner_id': l and l.order_id.partner_id.id or False,
99 'company_id': procurement.company_id.id,
100 'project_id': project_id,
102 self.write(cr, uid, [procurement.id],{'task_id':task_id})
103 product_obj.write(cr,uid,[procurement.product_id.id],{'project_id':project_id})
108 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: