[MERGE] New menus. Get rid of jQuery accordion. Added folding and floating menus.
[odoo/odoo.git] / addons / mrp_repair / wizard / cancel_repair.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #    
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.     
19 #
20 ##############################################################################
21
22 from osv import osv,fields
23 from tools.translate import _
24
25 class repair_cancel(osv.osv_memory):
26     _name = 'mrp.repair.cancel'
27     _description = 'Cancel Repair'
28
29     def cancel_repair(self, cr, uid, ids, context=None):
30         """ Cancels the repair
31         @param self: The object pointer.
32         @param cr: A database cursor
33         @param uid: ID of the user currently logged in
34         @param ids: List of IDs selected 
35         @param context: A standard dictionary 
36         @return:  
37         """
38         if context is None:
39             context = {}
40         record_id = context and context.get('active_id', False) or False
41         assert record_id, _('Active ID is not Found')
42         repair_order_obj = self.pool.get('mrp.repair')
43         repair_line_obj = self.pool.get('mrp.repair.line')
44         repair_order = repair_order_obj.browse(cr, uid, record_id, context=context)
45         
46         if repair_order.invoiced or repair_order.invoice_method == 'none':
47             repair_order_obj.action_cancel(cr, uid, [record_id], context=context)            
48         else:
49             raise osv.except_osv(_('Warning!'),_('Repair order is not invoiced.'))
50         
51         return {'type': 'ir.actions.act_window_close'}
52     
53     def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
54         """ Changes the view dynamically
55         @param self: The object pointer.
56         @param cr: A database cursor
57         @param uid: ID of the user currently logged in
58         @param context: A standard dictionary 
59         @return: New arch of view.
60         """
61         if context is None:
62             context = {}
63         res = super(repair_cancel, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
64         record_id = context and context.get('active_id', False) or False        
65         active_model = context.get('active_model')
66         
67         if not record_id or (active_model and active_model != 'mrp.repair'):
68             return res
69         
70         repair_order = self.pool.get('mrp.repair').browse(cr, uid, record_id, context=context)
71         if not repair_order.invoiced:
72             res['arch'] = """ <form string="Cancel Repair" colspan="4">
73                             <group col="2" colspan="2">
74                                 <label string="Do you want to continue?" colspan="4"/>
75                                 <separator colspan="4"/>
76                                 <button icon="gtk-stop" special="cancel" string="_No" readonly="0"/>
77                                 <button name="cancel_repair" string="_Yes" type="object" icon="gtk-ok"/>
78                             </group>
79                         </form>                             
80                     """
81         return res
82
83 repair_cancel()
84
85 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
86