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
23
from tools.translate import _
25
class stock_picking(osv.osv):
27
Override the class stock_picking to replace the standard
28
delete button by a delete button of type "object"
30
_name = 'stock.picking'
31
_inherit = 'stock.picking'
33
def unlink(self, cr, uid, ids, context=None):
35
The deletion is possible only for draft document that are not generated by the system,
36
i.e. that doesn't come from a PO or a SO => the check is done in msf_outgoing>msf_outgoing.py
38
if isinstance(ids, (int, long)):
40
for sp in self.read(cr, uid, ids,['state'], context=context):
41
if sp['state'] == 'draft':
42
return super(stock_picking, self).unlink(cr, uid, ids, context)
44
raise osv.except_osv(_('Warning !'), _('You can only delete documents which are in "Draft" state.'))
46
def delete_button(self, cr, uid, ids, context=None):
48
This method is called on the button of type object in tree view.
49
The aim is to be able to display the delete button only in draft state, which is not possible with the standard delete button.
51
if isinstance(ids, (int, long)):
53
return self.unlink(cr, uid, ids, context)
57
class purchase_order(osv.osv):
59
Override the class purchase_order to replace the standard
60
delete button by a delete button of type "object"
62
_name = 'purchase.order'
63
_inherit = 'purchase.order'
65
def unlink(self, cr, uid, ids, context=None):
67
Don't allow user to delete purchase order in draft state
69
if isinstance(ids, (int, long)):
71
for p in self.read(cr, uid, ids,['state'], context=context):
72
if p['state'] == 'draft':
73
return super(purchase_order, self).unlink(cr, uid, ids, context)
75
raise osv.except_osv(_('Warning !'), _('You can only delete documents which are in "Draft" state.'))
77
def delete_button(self, cr, uid, ids, context=None):
79
This method is called on the button of type object in tree view.
80
The aim is to be able to display the delete button only in draft state, which is not possible with the standard delete button.
82
if isinstance(ids, (int, long)):
84
return self.unlink(cr, uid, ids, context)
88
class sale_order(osv.osv):
90
Override the class sale_order to replace the standard
91
delete button by a delete button of type "object"
94
_inherit = 'sale.order'
96
def unlink(self, cr, uid, ids, context=None):
98
Do not allow user to delete sale order in draft state
100
if isinstance(ids, (int, long)):
102
for order in self.read(cr, uid, ids,['state'], context=context):
103
if order['state'] == 'draft':
104
return super(sale_order, self).unlink(cr, uid, ids, context)
106
raise osv.except_osv(_('Warning !'), _('You can only delete documents which are in "Draft" state.'))
108
def delete_button(self, cr, uid, ids, context=None):
110
This method is called on the button of type object in tree view.
111
The aim is to be able to display the delete button only in draft state, which is not possible with the standard delete button.
113
if isinstance(ids, (int, long)):
115
return self.unlink(cr, uid, ids, context)
119
class tender(osv.osv):
121
Override the class tender to replace the standard
122
delete button by a delete button of type "object"
127
def unlink(self, cr, uid, ids, context=None):
129
Do not allow user to delete tender in draft state
131
if isinstance(ids, (int, long)):
133
for order in self.read(cr, uid, ids,['state'], context=context):
134
if order['state'] == 'draft':
135
return super(tender, self).unlink(cr, uid, ids, context)
137
raise osv.except_osv(_('Warning !'), _('You can only delete documents which are in "Draft" state.'))
139
def delete_button(self, cr, uid, ids, context=None):
141
This method is called on the button of type object in tree view.
142
The aim is to be able to display the delete button only in draft state, which is not possible with the standard delete button.
144
if isinstance(ids, (int, long)):
146
return self.unlink(cr, uid, ids, context)
150
class composition_kit(osv.osv):
152
Override the class composition_kit to replace the standard
153
delete button by a delete button of type "object"
155
_name = 'composition.kit'
156
_inherit = 'composition.kit'
158
def unlink(self, cr, uid, ids, context=None):
160
Do not allow user to delete composition_kit in draft state
162
if isinstance(ids, (int, long)):
164
for order in self.read(cr, uid, ids,['state'], context=context):
165
if order['state'] == 'draft':
166
return super(composition_kit, self).unlink(cr, uid, ids, context)
168
raise osv.except_osv(_('Warning !'), _('You can only delete documents which are in "Draft" state.'))
170
def delete_button(self, cr, uid, ids, context=None):
172
This method is called on the button of type object in tree view.
173
The aim is to be able to display the delete button only in draft state, which is not possible with the standard delete button.
175
if isinstance(ids, (int, long)):
177
return self.unlink(cr, uid, ids, context)
181
class real_average_consumption(osv.osv):
182
_name = 'real.average.consumption'
183
_inherit = 'real.average.consumption'
185
def delete_button(self, cr, uid, ids, context=None):
187
This method is called on the button of type object in tree view.
188
The aim is to be able to display the delete button only in draft state, which is not possible with the standard delete button.
190
if isinstance(ids, (int, long)):
192
return self.unlink(cr, uid, ids, context)
194
real_average_consumption()