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 ##############################################################################
23 from osv import fields, osv
26 from osv.orm import browse_record, browse_null
27 from tools.translate import _
29 class purchase_order_group(osv.osv_memory):
30 _name = "purchase.order.group"
31 _description = "Purchase Order Merge"
33 def fields_view_get(self, cr, uid, view_id=None, view_type='form',
34 context=None, toolbar=False, submenu=False):
36 Changes the view dynamically
37 @param self: The object pointer.
38 @param cr: A database cursor
39 @param uid: ID of the user currently logged in
40 @param context: A standard dictionary
41 @return: New arch of view.
45 res = super(purchase_order_group, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
46 if context.get('active_model','') == 'purchase.order' and len(context['active_ids']) < 2:
47 raise osv.except_osv(_('Warning'),
48 _('Please select multiple order to merge in the list view.'))
50 def merge_orders(self, cr, uid, ids, context=None):
52 To merge similar type of purchase orders.
54 @param self: The object pointer.
55 @param cr: A database cursor
56 @param uid: ID of the user currently logged in
57 @param ids: the ID or list of IDs
58 @param context: A standard dictionary
60 @return: purchase order view
63 order_obj = self.pool.get('purchase.order')
64 proc_obj = self.pool.get('procurement.order')
65 mod_obj =self.pool.get('ir.model.data')
68 result = mod_obj._get_id(cr, uid, 'purchase', 'view_purchase_order_filter')
69 id = mod_obj.read(cr, uid, result, ['res_id'])
71 allorders = order_obj.do_merge(cr, uid, context.get('active_ids',[]), context)
72 for new_order in allorders:
73 proc_ids = proc_obj.search(cr, uid, [('purchase_id', 'in', allorders[new_order])], context=context)
74 for proc in proc_obj.browse(cr, uid, proc_ids, context=context):
76 proc_obj.write(cr, uid, [proc.id], {'purchase_id': new_order}, context)
79 'domain': "[('id','in', [" + ','.join(map(str, allorders.keys())) + "])]",
80 'name': _('Purchase Orders'),
82 'view_mode': 'tree,form',
83 'res_model': 'purchase.order',
85 'type': 'ir.actions.act_window',
86 'search_view_id': id['res_id']
89 purchase_order_group()
91 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: