~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to specific_rules/specific_rules.py

  • Committer: chloups208
  • Date: 2011-08-25 12:15:38 UTC
  • mto: This revision was merged to the branch mainline in revision 264.
  • Revision ID: chloups208@chloups208-laptop-20110825121538-bsiqzhugwziwwtqr
[UF-372]warehouse wizards

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
import pooler
30
30
import time
31
31
 
 
32
# warning messages
 
33
SHORT_SHELF_LIFE_MESS = 'Product with Short Shelf Life, check the accuracy of the order quantity, frequency and mode of transport.'
 
34
 
 
35
 
32
36
class sale_order_line(osv.osv):
33
37
    '''
34
38
    override to add message at sale order creation and update
35
39
    '''
36
40
    _inherit = 'sale.order.line'
37
41
    
38
 
#    def create(self, cr, uid, vals, context=None):
39
 
#        '''
40
 
#        display message for short shelf life things
41
 
#        '''
42
 
#        sol_id = super(sale_order_line, self).create(cr, uid, vals, context=context)
43
 
#        sol = self.browse(cr, uid, sol_id, context=context)
44
 
#        # log the message
45
 
#        if sol.product_id.short_shelf_life:
46
 
#            self.log(cr, uid, sol_id, 'Product with short shelf life, check the accuracy of the order quantity, frequency and mode of transport.', context=context)
47
 
#        
48
 
#        return sol_id
49
 
    
50
 
#    def write(self, cr, uid, ids, vals, context=None):
51
 
#        '''
52
 
#        display message for short shelf life things
53
 
#        '''
54
 
#        if isinstance(ids, (int, long)):
55
 
#            ids = [ids]
56
 
#            
57
 
#        result = super(sale_order_line, self).write(cr, uid, ids, vals, context=context)
58
 
#            
59
 
#        for sol in self.browse(cr, uid, ids, context=context):
60
 
#            # log the message
61
 
#            if sol.product_id.short_shelf_life:
62
 
#                # log the message
63
 
#                self.log(cr, uid, sol.id, 'Product with short shelf life, check the accuracy of the order quantity, frequency and mode of transport.', context=context)
64
 
#            
65
 
#        return result
 
42
    
 
43
    def _kc_dg(self, cr, uid, ids, name, arg, context=None):
 
44
        '''
 
45
        return 'KC' if cold chain or 'DG' if dangerous goods
 
46
        '''
 
47
        result = {}
 
48
        for id in ids:
 
49
            result[id] = ''
 
50
            
 
51
        for sol in self.browse(cr, uid, ids, context=context):
 
52
            if sol.product_id:
 
53
                if sol.product_id.heat_sensitive_item:
 
54
                    result[sol.id] = 'KC'
 
55
                elif sol.product_id.dangerous_goods:
 
56
                    result[sol.id] = 'DG'
 
57
        
 
58
        return result
 
59
        
 
60
    _columns = {'kc_dg': fields.function(_kc_dg, method=True, string='KC/DG', type='char'),}
 
61
    
 
62
    def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
 
63
            uom=False, qty_uos=0, uos=False, name='', partner_id=False,
 
64
            lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False):
 
65
        '''
 
66
        
 
67
        '''
 
68
        # call to super
 
69
        result = super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty,
 
70
            uom, qty_uos, uos, name, partner_id, lang, update_tax, date_order, packaging, fiscal_position, flag)
 
71
        
 
72
        # if the product is short shelf life, display a warning
 
73
        if product:
 
74
            prod_obj = self.pool.get('product.product')
 
75
            if prod_obj.browse(cr, uid, product).short_shelf_life:
 
76
                warning = {
 
77
                            'title': 'Short Shelf Life product',
 
78
                            'message': SHORT_SHELF_LIFE_MESS
 
79
                            }
 
80
                result.update(warning=warning)
 
81
            
 
82
        return result
66
83
    
67
84
sale_order_line()
68
85
 
69
86
class sale_order(osv.osv):
70
87
    '''
71
 
    
 
88
    add message when so is written, i.e when we add new so lines
72
89
    '''
73
90
    _inherit = 'sale.order'
74
91
    
84
101
                # log the message
85
102
                if line.product_id.short_shelf_life:
86
103
                    # log the message
87
 
                    self.log(cr, uid, obj.id, 'Product with Short Shelf Life, check the accuracy of the order quantity, frequency and mode of transport.', context=context)
 
104
                    self.log(cr, uid, obj.id, SHORT_SHELF_LIFE_MESS)
88
105
        
89
106
        return super(sale_order, self).write(cr, uid, ids, vals, context=context)
90
107
    
93
110
 
94
111
class purchase_order(osv.osv):
95
112
    '''
 
113
    add message when po is written, i.e when we add new po lines
96
114
    
 
115
    no need to modify the wkf_confirm_order as the wrtie method is called during the workflow
97
116
    '''
98
117
    _inherit = 'purchase.order'
99
118
    
100
 
#    def wkf_confirm_order(self, cr, uid, ids, context=None):
101
 
#        '''
102
 
#        
103
 
#        '''
104
 
#        result = super(purchase_order, self).wkf_confirm_order(cr, uid, ids, context=context)
105
 
#        
106
 
#        # display message
107
 
#        
108
 
#        return result
109
 
    
110
119
    def write(self, cr, uid, ids, vals, context=None):
111
120
        '''
112
121
        display message if contains short shelf life
119
128
                # log the message
120
129
                if line.product_id.short_shelf_life:
121
130
                    # log the message
122
 
                    self.log(cr, uid, obj.id, 'Product with Short Shelf Life, check the accuracy of the order quantity, frequency and mode of transport.', context=context)
 
131
                    self.log(cr, uid, obj.id, SHORT_SHELF_LIFE_MESS)
123
132
        
124
133
        return super(purchase_order, self).write(cr, uid, ids, vals, context=context)
125
134
    
126
135
purchase_order()
127
 
    
 
136
 
 
137
 
 
138
class stock_warehouse_orderpoint(osv.osv):
 
139
    '''
 
140
    add message
 
141
    '''
 
142
    _inherit = 'stock.warehouse.orderpoint'
 
143
    
 
144
    def create(self, cr, uid, vals, context=None):
 
145
        '''
 
146
        add message
 
147
        '''
 
148
        new_id = super(stock_warehouse_orderpoint, self).create(cr, uid, vals, context=context)
 
149
        
 
150
        product_obj = self.pool.get('product.product')
 
151
        product_id = vals.get('product_id', False)
 
152
        if product_id:
 
153
            if product_obj.browse(cr, uid, product_id, context=context).short_shelf_life:
 
154
                self.log(cr, uid, new_id, SHORT_SHELF_LIFE_MESS)
 
155
                
 
156
        return new_id
 
157
    
 
158
    def write(self, cr, uid, ids, vals, context=None):
 
159
        '''
 
160
        add message
 
161
        '''
 
162
        result = super(stock_warehouse_orderpoint, self).write(cr, uid, ids, vals, context=context)
 
163
        
 
164
        product_obj = self.pool.get('product.product')
 
165
        product_id = vals.get('product_id', False)
 
166
        if product_id:
 
167
            if product_obj.browse(cr, uid, product_id, context=context).short_shelf_life:
 
168
                for obj in self.browse(cr, uid, ids, context=context):
 
169
                    self.log(cr, uid, obj.id, SHORT_SHELF_LIFE_MESS)
 
170
        
 
171
        return result
 
172
        
 
173
stock_warehouse_orderpoint()
 
174
 
 
175
 
 
176
class stock_warehouse_automatic_supply(osv.osv):
 
177
    '''
 
178
    add message
 
179
    '''
 
180
    _inherit = 'stock.warehouse.automatic.supply'
 
181
    
 
182
    def create(self, cr, uid, vals, context=None):
 
183
        '''
 
184
        add message
 
185
        '''
 
186
        new_id = super(stock_warehouse_automatic_supply, self).create(cr, uid, vals, context=context)
 
187
        
 
188
        product_obj = self.pool.get('product.product')
 
189
        product_id = vals.get('product_id', False)
 
190
        if product_id:
 
191
            if product_obj.browse(cr, uid, product_id, context=context).short_shelf_life:
 
192
                self.log(cr, uid, new_id, SHORT_SHELF_LIFE_MESS)
 
193
                
 
194
        return new_id
 
195
    
 
196
    def write(self, cr, uid, ids, vals, context=None):
 
197
        '''
 
198
        add message
 
199
        '''
 
200
        result = super(stock_warehouse_automatic_supply, self).write(cr, uid, ids, vals, context=context)
 
201
        
 
202
        product_obj = self.pool.get('product.product')
 
203
        product_id = vals.get('product_id', False)
 
204
        if product_id:
 
205
            if product_obj.browse(cr, uid, product_id, context=context).short_shelf_life:
 
206
                for obj in self.browse(cr, uid, ids, context=context):
 
207
                    self.log(cr, uid, obj.id, SHORT_SHELF_LIFE_MESS)
 
208
        
 
209
        return result
 
210
    
 
211
stock_warehouse_automatic_supply()
 
212
 
 
213
 
 
214
class stock_warehouse_order_cycle(osv.osv):
 
215
    '''
 
216
    add message
 
217
    '''
 
218
    _inherit = 'stock.warehouse.order.cycle'
 
219
    
 
220
    def create(self, cr, uid, vals, context=None):
 
221
        '''
 
222
        add message
 
223
        '''
 
224
        new_id = super(stock_warehouse_order_cycle, self).create(cr, uid, vals, context=context)
 
225
        
 
226
        product_obj = self.pool.get('product.product')
 
227
        product_id = vals.get('product_id', False)
 
228
        if product_id:
 
229
            if product_obj.browse(cr, uid, product_id, context=context).short_shelf_life:
 
230
                self.log(cr, uid, new_id, SHORT_SHELF_LIFE_MESS)
 
231
                
 
232
        return new_id
 
233
    
 
234
    def write(self, cr, uid, ids, vals, context=None):
 
235
        '''
 
236
        add message
 
237
        '''
 
238
        if context is None:
 
239
            context = {}
 
240
            
 
241
        result = super(stock_warehouse_order_cycle, self).write(cr, uid, ids, vals, context=context)
 
242
        
 
243
        product_obj = self.pool.get('product.product')
 
244
        product_id = vals.get('product_id', False)
 
245
        if product_id:
 
246
            if product_obj.browse(cr, uid, product_id, context=context).short_shelf_life:
 
247
                for obj in self.browse(cr, uid, ids, context=context):
 
248
                    self.log(cr, uid, obj.id, SHORT_SHELF_LIFE_MESS)
 
249
        
 
250
        return result
 
251
    
 
252
stock_warehouse_order_cycle()
 
253
 
 
254
 
 
255
class stock_move(osv.osv):
 
256
    '''
 
257
    add kc/dg
 
258
    '''
 
259
    _inherit = 'stock.move'
 
260
 
 
261
    def _kc_dg(self, cr, uid, ids, name, arg, context=None):
 
262
        '''
 
263
        return 'KC' if cold chain or 'DG' if dangerous goods
 
264
        '''
 
265
        result = {}
 
266
        for id in ids:
 
267
            result[id] = ''
 
268
            
 
269
        for move in self.browse(cr, uid, ids, context=context):
 
270
            if move.product_id:
 
271
                if move.product_id.heat_sensitive_item:
 
272
                    result[move.id] = 'KC'
 
273
                elif move.product_id.dangerous_goods:
 
274
                    result[move.id] = 'DG'
 
275
        
 
276
        return result
 
277
        
 
278
    _columns = {'kc_dg': fields.function(_kc_dg, method=True, string='KC/DG', type='char'),}
 
279
 
 
280
stock_move()
 
281
 
 
282
 
 
283
class stock_production_lot(osv.osv):
 
284
    '''
 
285
    productin lot modifications
 
286
    '''
 
287
    _inherit = 'stock.production.lot'
 
288
    
 
289
    def product_id_change(self, cr, uid, ids, product_id, context=None):
 
290
        '''
 
291
        complete the life_date attribute
 
292
        '''
 
293
        product_obj = self.pool.get('product.product')
 
294
        values = {}
 
295
        if product_id:
 
296
            duration = product_obj.browse(cr, uid, product_id, context=context).life_time
 
297
            date = datetime.today() + relativedelta(months=duration)
 
298
            values.update(life_date=date.strftime('%Y-%m-%d'))
 
299
            
 
300
        return {'value':values}
 
301
    
 
302
    def create_sequence(self, cr, uid, vals, context=None):
 
303
        """
 
304
        Create new entry sequence for every new order
 
305
        @param cr: cursor to database
 
306
        @param user: id of current user
 
307
        @param ids: list of record ids to be process
 
308
        @param context: context arguments, like lang, time zone
 
309
        @return: return a result
 
310
        """
 
311
        seq_pool = self.pool.get('ir.sequence')
 
312
        seq_typ_pool = self.pool.get('ir.sequence.type')
 
313
 
 
314
        name = 'Production Lot'
 
315
        code = 'stock.production.lot'
 
316
 
 
317
        types = {
 
318
            'name': name,
 
319
            'code': code
 
320
        }
 
321
        seq_typ_pool.create(cr, uid, types)
 
322
 
 
323
        seq = {
 
324
            'name': name,
 
325
            'code': code,
 
326
            'prefix': '',
 
327
            'padding': 0,
 
328
        }
 
329
        return seq_pool.create(cr, uid, seq)
 
330
    
 
331
    def create(self, cr, uid, vals, context=None):
 
332
        '''
 
333
        create the sequence for the version management
 
334
        '''
 
335
        sequence = self.create_sequence(cr, uid, vals, context=context)
 
336
        vals.update({'sequence_id': sequence})
 
337
        
 
338
        return super(stock_production_lot, self).create(cr, uid, vals, context=context)
 
339
    
 
340
    def write(self, cr, uid, ids, vals, context=None):
 
341
        '''
 
342
        update the sequence for the version management
 
343
        '''
 
344
        revision_obj = self.pool.get('stock.production.lot.revision')
 
345
        
 
346
        for lot in self.browse(cr, uid, ids, context=context):
 
347
           # create revision object for each lot
 
348
           version_number = lot.sequence_id.get_id(test='id', context=context)
 
349
           values = {'name': 'Auto Revision Logging',
 
350
                     'description': 'The production lot has been modified, this revision log has been created automatically.',
 
351
                     'date': time.strftime('%Y-%m-%d'),
 
352
                     'indice': version_number,
 
353
                     'author_id': uid,
 
354
                     'lot_id': lot.id,}
 
355
           revision_obj.create(cr, uid, values, context=context)
 
356
        
 
357
        return super(stock_production_lot, self).write(cr, uid, ids, vals, context=context)
 
358
    
 
359
    def remove_flag(self, flag, list):
 
360
        '''
 
361
        if we do not remove the flag, we fall into an infinite loop
 
362
        '''
 
363
        i = 0
 
364
        to_del = []
 
365
        for arg in list:
 
366
            if arg[0] == flag:
 
367
                to_del.append(i)
 
368
            i+=1
 
369
        for i in to_del:
 
370
            list.pop(i)
 
371
        
 
372
        return True
 
373
    
 
374
    def search_check_type(self, cr, uid, obj, name, args, context=None):
 
375
        '''
 
376
        modify the query to take the type of prodlot into account according to product's attributes
 
377
        'Batch Number mandatory' and 'Expiry Date Mandatory'
 
378
        
 
379
        if batch management: display only 'standard' lot
 
380
        if expiry and not batch management: display only 'internal' lot
 
381
        else: display normally
 
382
        '''
 
383
        product_obj = self.pool.get('product.product')
 
384
        product_id = context.get('product_id', False)
 
385
        
 
386
        # remove flag avoid infinite loop
 
387
        self.remove_flag('check_type', args)
 
388
            
 
389
        if not product_id:
 
390
            return args
 
391
        
 
392
        # check the product
 
393
        product = product_obj.browse(cr, uid, product_id, context=context)
 
394
 
 
395
        if product.batch_management:
 
396
            # standard lots
 
397
            args.append(('type', '=', 'standard'))
 
398
        elif product.perishable:
 
399
            # internal lots
 
400
            args.append(('type', '=', 'internal'))
 
401
            
 
402
        return args
 
403
    
 
404
    def _get_false(self, cr, uid, ids, field_name, arg, context=None):
 
405
        '''
 
406
        return false for each id
 
407
        '''
 
408
        if isinstance(ids,(long, int)):
 
409
           ids = [ids]
 
410
        
 
411
        result = {}
 
412
        for id in ids:
 
413
          result[id] = False
 
414
        return result
 
415
    
 
416
    _columns = {'check_type': fields.function(_get_false, fnct_search=search_check_type, string='Check Type', type="boolean", readonly=True, method=True),
 
417
                'type': fields.selection([('internal', 'Internal'), ('standard', 'Standard'),], string="Type"),
 
418
                'expiry_date': fields.date('Expiry Date'),
 
419
                'name': fields.char('Batch Number', size=1024, required=True, help="Unique production lot, will be displayed as: PREFIX/SERIAL [INT_REF]"),
 
420
                'date': fields.datetime('Auto Creation Date', required=True),
 
421
                'sequence_id': fields.many2one('ir.sequence', 'Lot Sequence', required=True,),}
 
422
    
 
423
    _defaults = {'type': 'standard',}
 
424
    _sql_constraints = [
 
425
        ('name_uniq', 'unique (name)', 'The Batch Number must be unique !'),
 
426
    ]
 
427
    
 
428
    def search(self, cr, uid, args=[], offset=0, limit=None, order=None, context={}, count=False):
 
429
        '''
 
430
        search function of production lot
 
431
        '''
 
432
        result = super(stock_production_lot, self).search(cr, uid, args, offset, limit, order, context, count)
 
433
        
 
434
        return result
 
435
    
 
436
stock_production_lot()
 
437
 
 
438
class stock_production_lot_revision(osv.osv):
 
439
    _inherit = 'stock.production.lot.revision'
 
440
    
 
441
    _order = 'indice desc'
 
442
    
 
443
stock_production_lot_revision()