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 osv,fields
23 from tools.translate import _
25 class repair_cancel(osv.osv_memory):
26 _name = 'mrp.repair.cancel'
27 _description = 'Cancel Repair'
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
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)
46 if repair_order.invoiced or repair_order.invoice_method == 'none':
47 repair_order_obj.action_cancel(cr, uid, [record_id], context=context)
49 raise osv.except_osv(_('Warning!'),_('Repair order is not invoiced.'))
51 return {'type': 'ir.actions.act_window_close'}
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.
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')
67 if not record_id or (active_model and active_model != 'mrp.repair'):
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"/>
85 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: