~stock-logistic-core-editors/stock-logistic-warehouse/7.0

« back to all changes in this revision

Viewing changes to stock_tracking_reopen/stock.py

  • Committer: Mathieu Vatel
  • Date: 2012-03-07 12:56:37 UTC
  • Revision ID: mathieu@julius.fr-20120307125637-oz14go5k32kyqn2f
Extra modules Julius V1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#################################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2011 Julius Network Solutions SARL <contact@julius.fr>
 
6
#
 
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.
 
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 General Public License for more details.
 
16
#
 
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/>.
 
19
#
 
20
#################################################################################
 
21
 
 
22
from osv import fields, osv
 
23
from tools.translate import _
 
24
import time
 
25
 
 
26
class stock_tracking(osv.osv):
 
27
    
 
28
    _inherit = 'stock.tracking'
 
29
 
 
30
    _columns = {
 
31
        'previous_id': fields.many2one('stock.tracking', 'Previous Pack', readonly=True),
 
32
        'modified': fields.boolean('Modified'),
 
33
    }
 
34
    
 
35
    _default = {
 
36
            'modified': False,
 
37
    }   
 
38
    '''Function for pack creation'''    
 
39
    def create_pack(self, cr, uid, ids, context=None):        
 
40
        '''Init'''
 
41
        if context == None:
 
42
            context = {}            
 
43
        '''Location determination'''
 
44
        stock_tracking_data = self.browse(cr, uid, ids[0])
 
45
        '''Pack Creation'''
 
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'''
 
48
        return tracking_id
 
49
    
 
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)
 
53
        for pack in pack_ids:                        
 
54
            if pack.state == 'open':
 
55
                self.pool.get('stock.tracking.history').create(cr, uid, {
 
56
                                'type': 'reopen',
 
57
                                'previous_ref': pack.name,
 
58
                                'tracking_id': pack.id
 
59
                                }, context)
 
60
        return True
 
61
 
 
62
    def set_close(self, cr, uid, ids, context=None):
 
63
        
 
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)
 
68
        if res:
 
69
            pack_ids = self.browse(cr, uid, ids, context)
 
70
            for pack in pack_ids:
 
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,
 
89
                                                                    })                            
 
90
                        '''end of loop''' 
 
91
                        if pack.child_ids:
 
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,
 
99
                                                                })
 
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,})
 
101
                        
 
102
                        self.write(cr, uid, [pack.id], {'state': 'close',
 
103
                                                        'active': False,
 
104
                                                        'modified': False})
 
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)
 
108
                        
 
109
                    self.write(cr, uid, [pack.id], {'state': 'close'})
 
110
        return res
 
111
 
 
112
stock_tracking()
 
113
 
 
114
class stock_tracking_history(osv.osv):
 
115
    
 
116
    _inherit = "stock.tracking.history"
 
117
    
 
118
    def _get_types(self, cr, uid, context={}):
 
119
        res = super(stock_tracking_history, self)._get_types(cr, uid, context)
 
120
        if not res:
 
121
            res = []
 
122
        res = res + [('reopen','Re Open')]
 
123
        return res
 
124
    
 
125
    _columns = {
 
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'),
 
129
    }
 
130
    
 
131
stock_tracking_history()
 
132
 
 
133
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
 
b'\\ No newline at end of file'