~jeffery9/stock-logistic-tracking/stock-logistic-tracking

« back to all changes in this revision

Viewing changes to stock_tracking_add_move/stock.py

  • Committer: Joël Grand-Guillaume
  • Author(s): alexandre.fayolle at camptocamp
  • Date: 2012-11-02 10:27:23 UTC
  • Revision ID: joel.grandguillaume@camptocamp.com-20121102102723-559ynl9cf8awxgqh
[IMP] Apply typo and pypi conformity from Alex

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from tools.translate import _
24
24
 
25
25
class stock_tracking(osv.osv):
26
 
    
 
26
 
27
27
    _inherit = 'stock.tracking'
28
28
 
29
29
    _columns = {
32
32
        'to_add': fields.one2many('stock.scan.to.validate', 'tracking_id', 'To add', domain=[('type','=','in')]),
33
33
        'to_remove': fields.one2many('stock.scan.to.validate', 'tracking_id', 'To validate', domain=[('type','=','out')]),
34
34
    }
35
 
        
 
35
 
36
36
    def add_validation(self, cr, uid, ids, barcode_ids, context=None):
37
 
        
 
37
 
38
38
        barcode_obj = self.pool.get('tr.barcode')
39
39
        tracking_obj = self.pool.get('stock.tracking')
40
40
        move_obj = self.pool.get('stock.move')
41
41
        product_obj = self.pool.get('product.product')
42
42
        history_obj = self.pool.get('stock.tracking.history')
43
43
        validate_obj = self.pool.get('stock.scan.to.validate')
44
 
        
 
44
 
45
45
        if context == None:
46
46
            context = {}
47
 
        if barcode_ids:            
 
47
        if barcode_ids:
48
48
            for obj in self.browse(cr, uid, ids):
49
49
                barcode = barcode_obj.browse(cr, uid, barcode_ids[0])
50
50
                model = barcode.res_model
51
51
                res_id = barcode.res_id
52
 
                
 
52
 
53
53
                if model == 'stock.tracking':
54
54
                    '''Pack Case'''
55
55
                    pack = tracking_obj.browse(cr, uid, res_id)
59
59
                        history_obj.create(cr, uid, {'type': 'pack_in',
60
60
                                                     'tracking_id': res_id,
61
61
                                                     'parent_id': obj.id,
62
 
                                                    })                        
 
62
                                                    })
63
63
                        tracking_obj.write(cr, uid, pack.id, {'location_id': obj.location_id and obj.location_id.id or False,})
64
64
                        tracking_obj.write(cr, uid, obj.id, {'modified': True})
65
65
                        for move_data in pack.move_ids:
93
93
                                                                    'location_dest_id': obj.location_id.id,
94
94
                                                                    })
95
95
                            move_obj.write(cr, uid, new_move_id, {'tracking_id': obj.id})
96
 
                            tracking_obj.write(cr, uid, obj.id, {'modified': True}) 
97
 
                        else:    
 
96
                            tracking_obj.write(cr, uid, obj.id, {'modified': True})
 
97
                        else:
98
98
                            move_obj.write(cr, uid, move_ids, {'tracking_id': obj.id})
99
 
                            tracking_obj.write(cr, uid, obj.id, {'modified': True})      
100
 
                        
 
99
                            tracking_obj.write(cr, uid, obj.id, {'modified': True})
 
100
 
101
101
                elif model == 'product.product':
102
 
                    '''Product Case'''                
103
 
                    pack = tracking_obj.browse(cr, uid, obj.id)  
104
 
                    product_data = product_obj.browse(cr, uid,res_id)                                 
 
102
                    '''Product Case'''
 
103
                    pack = tracking_obj.browse(cr, uid, obj.id)
 
104
                    product_data = product_obj.browse(cr, uid,res_id)
105
105
                    move_id = move_obj.create(cr, uid, {
106
106
                                              'name': product_data.name,
107
107
                                              'product_id': product_data.id,
110
110
                                              'location_dest_id': pack.location_id.id,
111
111
                                              'tracking_id': obj.id,
112
112
                                              'state': 'draft',
113
 
                                            })                        
114
 
                    tracking_obj.write(cr, uid, obj.id, {'modified': True})          
115
 
                        
116
 
            '''Call for a function who will display serial code list and product list in the pack layout'''                                                
 
113
                                            })
 
114
                    tracking_obj.write(cr, uid, obj.id, {'modified': True})
 
115
 
 
116
            '''Call for a function who will display serial code list and product list in the pack layout'''
117
117
            tracking_obj.get_products(cr, uid, ids, context=None)
118
 
            tracking_obj.get_serials(cr, uid, ids, context=None)   
 
118
            tracking_obj.get_serials(cr, uid, ids, context=None)
119
119
        else:
120
120
            raise osv.except_osv(_('Warning!'),_('Barcode Not found!'))
121
121
        return {}
122
 
    
 
122
 
123
123
    def remove_validation(self, cr, uid, ids, barcode_ids, context=None):
124
124
        barcode_obj = self.pool.get('tr.barcode')
125
125
        tracking_obj = self.pool.get('stock.tracking')
127
127
        product_obj = self.pool.get('product.product')
128
128
        history_obj = self.pool.get('stock.tracking.history')
129
129
        validate_obj = self.pool.get('stock.scan.to.validate')
130
 
        
 
130
 
131
131
        if context == None:
132
132
            context = {}
133
133
        if barcode_ids:
140
140
                    pack = tracking_obj.browse(cr, uid, res_id)
141
141
                    tracking_obj.write(cr, uid, res_id, {'parent_id': False})
142
142
                    tracking_obj.write(cr, uid, obj.id, {'modified': True})
143
 
                elif model == 'stock.production.lot':    
 
143
                elif model == 'stock.production.lot':
144
144
                    pack = tracking_obj.browse(cr, uid, obj.id)
145
145
                    move_ids = move_obj.search(cr, uid, [
146
146
                                     ('prodlot_id', '=', res_id),
147
147
                                     ], limit=1)
148
148
                    if move_ids:
149
149
                        move_obj.write(cr, uid, move_ids, {'tracking_id': False})
150
 
                        tracking_obj.write(cr, uid, obj.id, {'modified': True})        
 
150
                        tracking_obj.write(cr, uid, obj.id, {'modified': True})
151
151
                elif model == 'product.product':
152
 
                    pack = tracking_obj.browse(cr, uid, obj.id)  
 
152
                    pack = tracking_obj.browse(cr, uid, obj.id)
153
153
                    product_data = product_obj.browse(cr, uid,res_id)
154
154
                    move_ids = move_obj.search(cr, uid, [
155
155
                                     ('product_id', '=', product_data.id),
156
 
                                     ], limit=1)     
 
156
                                     ], limit=1)
157
157
                    if move_ids:
158
158
                        move_obj.write(cr, uid, move_ids, {'tracking_id': False})
159
 
                        tracking_obj.write(cr, uid, obj.id, {'modified': True})                           
160
 
                    
 
159
                        tracking_obj.write(cr, uid, obj.id, {'modified': True})
 
160
 
161
161
            '''Call for a function who will display serial code list and product list in the pack layout'''
162
162
            tracking_obj.get_serials(cr, uid, ids, context=None)
163
 
            tracking_obj.get_products(cr, uid, ids, context=None)            
 
163
            tracking_obj.get_products(cr, uid, ids, context=None)
164
164
        else:
165
165
            raise osv.except_osv(_('Warning!'),_('Barcode Not found!'))
166
 
        return {}     
 
166
        return {}
167
167
 
168
168
stock_tracking()
169
169
 
170
170
class stock_scan_to_validate(osv.osv):
171
 
    
 
171
 
172
172
    _name = 'stock.scan.to.validate'
173
173
    _columns = {
174
174
        'tracking_id': fields.many2one('stock.tracking', 'Parent', readonly=True),
175
175
        'type': fields.selection([('in','To add'),('out','To remove')], 'Type', readonly=True),
176
176
        'barcode_id': fields.many2one('tr.barcode', 'Barcode', readonly=True),
177
177
    }
178
 
    
 
178
 
179
179
    _sql_constraints = [
180
180
        ('tracking_barcode_unique', 'unique (tracking_id,barcode_id)', 'This barcode is already in the list to add or to remove !')
181
181
    ]
183
183
stock_scan_to_validate()
184
184
 
185
185
class stock_tracking_history(osv.osv):
186
 
    
 
186
 
187
187
    _inherit = "stock.tracking.history"
188
 
    
 
188
 
189
189
    def _get_types(self, cr, uid, context={}):
190
190
        res = super(stock_tracking_history, self)._get_types(cr, uid, context)
191
191
        if not res:
192
192
            res = []
193
193
        res = res + [('pack_in','Add parent'),('pack_out','Unlink parent')]
194
194
        return res
195
 
    
 
195
 
196
196
    _columns = {
197
197
        'type': fields.selection(_get_types, 'Type'),
198
198
        'parent_id': fields.many2one('stock.tracking', 'Parent pack'),
199
199
    }
200
 
    
 
200
 
201
201
stock_tracking_history()
202
202
 
203
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
 
b'\\ No newline at end of file'
 
203
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: