1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2011 MSF, TeMPO Consulting
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import osv, fields
from tools.translate import _
class stock_warehouse(osv.osv):
'''
add a new field quarantine which is not mandatory
'''
_inherit = 'stock.warehouse'
_columns = {'lot_quarantine_id': fields.many2one('stock.location', 'Location Quarantine', domain=[('usage','<>','view'), ('quarantine_location', '=', True),]),
}
stock_warehouse()
class stock_location(osv.osv):
'''
override stock location to add:
- quarantine location (checkbox - boolean)
- destruction location (checkbox - boolean)
- location category (selection)
'''
_inherit = 'stock.location'
def remove_flag(self, flag, list):
'''
if we do not remove the flag, we fall into an infinite loop
'''
i = 0
to_del = []
for arg in list:
if arg[0] == flag:
to_del.append(i)
i+=1
for i in to_del:
list.pop(i)
return True
def search_check_quarantine(self, cr, uid, obj, name, args, context=None):
'''
modify the query to take the type of stock move into account
if type is 'out', quarantine_location must be False
'''
move_obj = self.pool.get('stock.move')
move_id = context.get('move_id', False)
# remove flag avoid infinite loop
self.remove_flag('check_quarantine', args)
if not move_id:
return args
# check the move
move = move_obj.browse(cr, uid, move_id, context=context)
if move.type == 'out':
# out -> not from quarantine
args.append(('quarantine_location', '=', False))
return args
def _get_false(self, cr, uid, ids, field_name, arg, context=None):
'''
return false for each id
'''
if isinstance(ids,(long, int)):
ids = [ids]
result = {}
for id in ids:
result[id] = False
return result
def _check_parent(self, cr, uid, ids, context=None):
"""
Quarantine Location can only have Quarantine Location or Views as parent location.
"""
for obj in self.browse(cr, uid, ids, context=context):
if obj.quarantine_location and obj.location_id:
if obj.location_id.usage not in ('view',) and not obj.location_id.quarantine_location:
return False
return True
def _check_chained(self, cr, uid, ids, context=None):
""" Checks if location is quarantine and chained loc
@return: True or False
"""
for obj in self.browse(cr, uid, ids, context=context):
if obj.quarantine_location:
if obj.chained_location_type != 'none':
return False
return True
_columns = {'quarantine_location': fields.boolean(string='Quarantine Location'),
'destruction_location': fields.boolean(string='Destruction Loction'),
'location_category': fields.selection([('stock', 'Stock'),
('consumption_unit', 'Consumption Unit'),
('transition', 'Transition'),
('other', 'Other'),], string='Location Category', required=True),
# could be used after discussion with Magali
#'check_quarantine': fields.function(_get_false, fnct_search=search_check_quarantine, string='Check Quarantine', type="boolean", readonly=True, method=True),
}
_defaults = {
'location_category': 'stock',
}
_constraints = [(_check_parent,
'Quarantine Location can only have Quarantine Location or Views as parent location.',
['location_id'],),
(_check_chained,
'You cannot define a quarantine location as chained location.',
['quarantine_location', 'chained_location_type'],),
]
stock_location()
class procurement_order(osv.osv):
_inherit = 'procurement.order'
def _do_create_proc_hook(self, cr, uid, ids, context=None, *args, **kwargs):
'''
hook to update defaults data
'''
# call super
values = super(procurement_order, self)._do_create_proc_hook(cr, uid, ids, context=context, *args, **kwargs)
# as location, we take the input of the warehouse
op = kwargs.get('op', False)
assert op, 'missing op'
# update location value
values.update(location_id=op.warehouse_id.lot_input_id.id)
return values
procurement_order()
class purchase_order(osv.osv):
'''
override purchase order
- add hook _hook_action_picking_create_modify_out_source_loc_check
'''
_inherit = 'purchase.order'
def _hook_action_picking_create_modify_out_source_loc_check(self, cr, uid, ids, context=None, *args, **kwargs):
'''
Please copy this to your module's method also.
This hook belongs to the action_picking_create method from purchase>purchase.py>purchase_order class
- allow to choose whether or not the source location of the corresponding outgoing stock move should
match the destination location of incoming stock move
'''
# we do not want the corresponding out stock move to be updated
return False
purchase_order()
class stock_move(osv.osv):
'''
add _hook_action_done_update_out_move_check
'''
_inherit = 'stock.move'
def _hook_action_done_update_out_move_check(self, cr, uid, ids, context=None, *args, **kwargs):
'''
choose if the corresponding out stock move must be updated
'''
result = super(stock_move, self)._hook_action_done_update_out_move_check(cr, uid, ids, context=context, *args, **kwargs)
# we never update the corresponding out stock move
return False
stock_move()
|