[REF] purchase: search view of purchase order and form view of merge order wizard
[odoo/odoo.git] / addons / purchase_tender / purchase_tender.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution    
5 #    Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
8 #    This program is free software: you can redistribute it and/or modify
9 #    it under the terms of the GNU General Public License as published by
10 #    the Free Software Foundation, either version 3 of the License, or
11 #    (at your option) any later version.
12 #
13 #    This program is distributed in the hope that it will be useful,
14 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #    GNU General Public License for more details.
17 #
18 #    You should have received a copy of the GNU General Public License
19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 ##############################################################################
22
23 from osv import fields,osv
24 from osv import orm
25 import netsvc
26 import time
27
28 class purchase_tender(osv.osv):
29     _name = "purchase.tender"
30     _description="Purchase Tender"
31     _columns = {
32         'name': fields.char('Tender Reference', size=32,required=True),
33         'date_start': fields.datetime('Date Start'),
34         'date_end': fields.datetime('Date End'),
35         'user_id': fields.many2one('res.users', 'Responsible'),
36         'description': fields.text('Description'),
37         'purchase_ids' : fields.one2many('purchase.order','tender_id','Purchase Orders'),
38         'state': fields.selection([('draft','Draft'),('open','Open'),('close','Close')], 'State', required=True)
39     }
40     _defaults = {
41         'date_start': lambda *args: time.strftime('%Y-%m-%d %H:%M:%S'),
42         'state': lambda *args: 'open',
43         'name': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'purchase.order.tender'),
44     }
45 purchase_tender()
46
47 class purchase_order(osv.osv):
48     _inherit = "purchase.order"
49     _description = "purchase order"
50     _columns = {
51         'tender_id' : fields.many2one('purchase.tender','Purchase Tender')
52     }
53     def wkf_confirm_order(self, cr, uid, ids, context={}):
54         res = super(purchase_order, self).wkf_confirm_order(cr, uid, ids, context)
55         for po in self.browse(cr, uid, ids, context):
56             if po.tender_id:
57                 for order in po.tender_id.purchase_ids:
58                     if order.id<>po.id:
59                         wf_service = netsvc.LocalService("workflow")
60                         wf_service.trg_validate(uid, 'purchase.order', order.id, 'purchase_cancel', cr)
61                     self.pool.get('purchase.tender').write(cr, uid, [po.tender_id.id], {'state':'close'})
62         return res
63 purchase_order()