1
# -*- coding: utf-8 -*-
2
#################################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 Julius Network Solutions SARL <contact@julius.fr>
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (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 General Public License for more details.
17
# You should have received a copy of the GNU 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 _
26
class stock_tracking(osv.osv):
28
_inherit = 'stock.tracking'
31
'previous_id': fields.many2one('stock.tracking', 'Previous Pack', readonly=True),
32
'modified': fields.boolean('Modified'),
38
'''Function for pack creation'''
39
def create_pack(self, cr, uid, ids, context=None):
43
'''Location determination'''
44
stock_tracking_data = self.browse(cr, uid, ids[0])
46
tracking_id = self.create(cr, uid, {'ul_id': stock_tracking_data.ul_id.id, 'location_id': stock_tracking_data.location_id.id})
47
'''Pack name is returned'''
50
def reset_open(self, cr, uid, ids, context=None):
51
res = super(stock_tracking, self).reset_open(cr, uid, ids, context)
52
pack_ids = self.browse(cr, uid, ids, context)
54
if pack.state == 'open':
55
self.pool.get('stock.tracking.history').create(cr, uid, {
57
'previous_ref': pack.name,
58
'tracking_id': pack.id
62
def set_close(self, cr, uid, ids, context=None):
64
barcode_obj = self.pool.get('tr.barcode')
65
stock_move_obj = self.pool.get('stock.move')
66
history_obj = self.pool.get('stock.tracking.history')
67
res = super(stock_tracking, self).set_close(cr, uid, ids, context)
69
pack_ids = self.browse(cr, uid, ids, context)
71
if pack.state == 'open':
72
if self.pool.get('stock.tracking.history').search(cr,uid,[('type','=','reopen'),('tracking_id','=',pack.id)]) and pack.modified == True:
73
new_pack_id = self.create_pack(cr, uid, ids, context)
74
new_pack_data = self.browse(cr, uid, new_pack_id, context)
75
'''loop on each move form the old pack to the new pack'''
76
for pack_move in pack.current_move_ids:
77
''''stock move creation'''
78
barcode_name = pack_move.prodlot_id.name
79
barcode_data = barcode_obj.search(cr, uid,[('code', '=', barcode_name)], limit=1)
80
move_id = stock_move_obj.create(cr, uid, {
81
'name': pack_move.name,
82
'state': pack_move.state,
83
'product_id': pack_move.product_id.id,
84
'product_uom': pack_move.product_uom.id,
85
'prodlot_id': pack_move.prodlot_id.id,
86
'location_id': pack.location_id.id,
87
'location_dest_id': new_pack_data.location_id.id,
88
'tracking_id': new_pack_data.id,
92
for child_pack_data in pack.child_ids:
93
if child_pack_data.state == 'close':
94
self.write(cr, uid, child_pack_data.id, {'active': False})
95
self.write(cr, uid, [new_child_pack_id], {'parent_id': new_pack_data.id,})
96
history_obj.create(cr, uid, {'type': 'pack_in',
97
'tracking_id': child_pack_data.id,
98
'parent_id': new_pack_data.id,
100
self.write(cr, uid, new_pack_data.id, {'location_id': child_pack_data.location_id and child_pack_data.location_id.id or False,})
102
self.write(cr, uid, [pack.id], {'state': 'close',
105
'''Call for a function who will display serial code list and product list in the pack layout'''
106
self.get_products(cr, uid, [new_pack_data.id], context=None)
107
self.get_serials(cr, uid, [new_pack_data.id], context=None)
109
self.write(cr, uid, [pack.id], {'state': 'close'})
114
class stock_tracking_history(osv.osv):
116
_inherit = "stock.tracking.history"
118
def _get_types(self, cr, uid, context={}):
119
res = super(stock_tracking_history, self)._get_types(cr, uid, context)
122
res = res + [('reopen','Re Open')]
126
'type': fields.selection(_get_types, 'Type'),
127
'previous_ref': fields.char('Previous reference', size=128),
128
# 'previous_id': fields.many2one('stock.tracking', 'Previous pack'),
131
stock_tracking_history()
133
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
b'\\ No newline at end of file'