33
SHORT_SHELF_LIFE_MESS = 'Product with Short Shelf Life, check the accuracy of the order quantity, frequency and mode of transport.'
32
36
class sale_order_line(osv.osv):
34
38
override to add message at sale order creation and update
36
40
_inherit = 'sale.order.line'
38
# def create(self, cr, uid, vals, context=None):
40
# display message for short shelf life things
42
# sol_id = super(sale_order_line, self).create(cr, uid, vals, context=context)
43
# sol = self.browse(cr, uid, sol_id, context=context)
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)
50
# def write(self, cr, uid, ids, vals, context=None):
52
# display message for short shelf life things
54
# if isinstance(ids, (int, long)):
57
# result = super(sale_order_line, self).write(cr, uid, ids, vals, context=context)
59
# for sol in self.browse(cr, uid, ids, context=context):
61
# if sol.product_id.short_shelf_life:
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)
43
def _kc_dg(self, cr, uid, ids, name, arg, context=None):
45
return 'KC' if cold chain or 'DG' if dangerous goods
51
for sol in self.browse(cr, uid, ids, context=context):
53
if sol.product_id.heat_sensitive_item:
55
elif sol.product_id.dangerous_goods:
60
_columns = {'kc_dg': fields.function(_kc_dg, method=True, string='KC/DG', type='char'),}
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):
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)
72
# if the product is short shelf life, display a warning
74
prod_obj = self.pool.get('product.product')
75
if prod_obj.browse(cr, uid, product).short_shelf_life:
77
'title': 'Short Shelf Life product',
78
'message': SHORT_SHELF_LIFE_MESS
80
result.update(warning=warning)
69
86
class sale_order(osv.osv):
88
add message when so is written, i.e when we add new so lines
73
90
_inherit = 'sale.order'
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)
124
133
return super(purchase_order, self).write(cr, uid, ids, vals, context=context)
138
class stock_warehouse_orderpoint(osv.osv):
142
_inherit = 'stock.warehouse.orderpoint'
144
def create(self, cr, uid, vals, context=None):
148
new_id = super(stock_warehouse_orderpoint, self).create(cr, uid, vals, context=context)
150
product_obj = self.pool.get('product.product')
151
product_id = vals.get('product_id', False)
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)
158
def write(self, cr, uid, ids, vals, context=None):
162
result = super(stock_warehouse_orderpoint, self).write(cr, uid, ids, vals, context=context)
164
product_obj = self.pool.get('product.product')
165
product_id = vals.get('product_id', False)
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)
173
stock_warehouse_orderpoint()
176
class stock_warehouse_automatic_supply(osv.osv):
180
_inherit = 'stock.warehouse.automatic.supply'
182
def create(self, cr, uid, vals, context=None):
186
new_id = super(stock_warehouse_automatic_supply, self).create(cr, uid, vals, context=context)
188
product_obj = self.pool.get('product.product')
189
product_id = vals.get('product_id', False)
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)
196
def write(self, cr, uid, ids, vals, context=None):
200
result = super(stock_warehouse_automatic_supply, self).write(cr, uid, ids, vals, context=context)
202
product_obj = self.pool.get('product.product')
203
product_id = vals.get('product_id', False)
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)
211
stock_warehouse_automatic_supply()
214
class stock_warehouse_order_cycle(osv.osv):
218
_inherit = 'stock.warehouse.order.cycle'
220
def create(self, cr, uid, vals, context=None):
224
new_id = super(stock_warehouse_order_cycle, self).create(cr, uid, vals, context=context)
226
product_obj = self.pool.get('product.product')
227
product_id = vals.get('product_id', False)
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)
234
def write(self, cr, uid, ids, vals, context=None):
241
result = super(stock_warehouse_order_cycle, self).write(cr, uid, ids, vals, context=context)
243
product_obj = self.pool.get('product.product')
244
product_id = vals.get('product_id', False)
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)
252
stock_warehouse_order_cycle()
255
class stock_move(osv.osv):
259
_inherit = 'stock.move'
261
def _kc_dg(self, cr, uid, ids, name, arg, context=None):
263
return 'KC' if cold chain or 'DG' if dangerous goods
269
for move in self.browse(cr, uid, ids, context=context):
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'
278
_columns = {'kc_dg': fields.function(_kc_dg, method=True, string='KC/DG', type='char'),}
283
class stock_production_lot(osv.osv):
285
productin lot modifications
287
_inherit = 'stock.production.lot'
289
def product_id_change(self, cr, uid, ids, product_id, context=None):
291
complete the life_date attribute
293
product_obj = self.pool.get('product.product')
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'))
300
return {'value':values}
302
def create_sequence(self, cr, uid, vals, context=None):
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
311
seq_pool = self.pool.get('ir.sequence')
312
seq_typ_pool = self.pool.get('ir.sequence.type')
314
name = 'Production Lot'
315
code = 'stock.production.lot'
321
seq_typ_pool.create(cr, uid, types)
329
return seq_pool.create(cr, uid, seq)
331
def create(self, cr, uid, vals, context=None):
333
create the sequence for the version management
335
sequence = self.create_sequence(cr, uid, vals, context=context)
336
vals.update({'sequence_id': sequence})
338
return super(stock_production_lot, self).create(cr, uid, vals, context=context)
340
def write(self, cr, uid, ids, vals, context=None):
342
update the sequence for the version management
344
revision_obj = self.pool.get('stock.production.lot.revision')
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,
355
revision_obj.create(cr, uid, values, context=context)
357
return super(stock_production_lot, self).write(cr, uid, ids, vals, context=context)
359
def remove_flag(self, flag, list):
361
if we do not remove the flag, we fall into an infinite loop
374
def search_check_type(self, cr, uid, obj, name, args, context=None):
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'
379
if batch management: display only 'standard' lot
380
if expiry and not batch management: display only 'internal' lot
381
else: display normally
383
product_obj = self.pool.get('product.product')
384
product_id = context.get('product_id', False)
386
# remove flag avoid infinite loop
387
self.remove_flag('check_type', args)
393
product = product_obj.browse(cr, uid, product_id, context=context)
395
if product.batch_management:
397
args.append(('type', '=', 'standard'))
398
elif product.perishable:
400
args.append(('type', '=', 'internal'))
404
def _get_false(self, cr, uid, ids, field_name, arg, context=None):
406
return false for each id
408
if isinstance(ids,(long, int)):
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,),}
423
_defaults = {'type': 'standard',}
425
('name_uniq', 'unique (name)', 'The Batch Number must be unique !'),
428
def search(self, cr, uid, args=[], offset=0, limit=None, order=None, context={}, count=False):
430
search function of production lot
432
result = super(stock_production_lot, self).search(cr, uid, args, offset, limit, order, context, count)
436
stock_production_lot()
438
class stock_production_lot_revision(osv.osv):
439
_inherit = 'stock.production.lot.revision'
441
_order = 'indice desc'
443
stock_production_lot_revision()