490
491
if row.cells[ed_cell_nb] and row.cells[ed_cell_nb].type == 'datetime' and row.cells[ed_cell_nb].data:
491
492
expiry_date = row.cells[ed_cell_nb].data
494
prd_brw = product_id and product_obj and product_obj.browse(cr, uid, product_id) or False
496
bn_mgmt = prd_brw and prd_brw.batch_management
497
ed_mgmt = prd_brw and prd_brw.perishable
493
499
if not bn_ids and product_id and batch_name and expiry_date:
494
500
bn_ids = bn_obj.search(cr, uid, [('product_id', '=', product_id), ('name', '=', batch_name), ('life_date', '=', expiry_date.strftime('%Y-%m-%d'))])
496
batch_number = bn_ids[0]
498
if not bn_ids and product_id and batch_name:
499
bn_ids = bn_obj.search(cr, uid, [('product_id', '=', product_id), ('name', '=', batch_name)])
501
batch_number = bn_ids[0]
503
# Set an error message for non matching between BN and Expiry date
505
warning_list.append(_('The expiry date %s not corresponding to the expiry date of the Batch Number %s - The expiry date of the batch has been set instead.') % (expiry_date.strftime(date_format), batch_name))
507
# Set expiry date with the life date of the BN
508
expiry_date = bn_obj.browse(cr, uid, batch_number).life_date
510
if not bn_ids and product_id and expiry_date:
511
bn_ids = bn_obj.search(cr, uid, [('product_id', '=', product_id), ('life_date', '=', expiry_date.strftime('%Y-%m-%d'))])
513
batch_number = bn_ids[0]
515
if (batch_name or expiry_date) and not bn_ids:
516
error_list.append(_('The Batch number was not found.'))
502
if bn_obj.search(cr, uid, [('product_id', '=', product_id), ('name', '=', batch_name)]):
504
error_list.append(_('The expiry date doesn\'t match with the expiry date of the batch. Batch not selected'))
506
error_list.append(_('The expiry date doesn\'t match with the expiry date of the batch. Expiry date not selected'))
508
error_list.append(_('Batch not found.'))
509
elif not bn_ids and product_id and expiry_date:
511
error_list.append(_('The Batch number is not set.'))
513
bn_ids = bn_obj.search(cr, uid, [('product_id', '=', product_id), ('life_date', '=', expiry_date.strftime('%Y-%m-%d'))])
514
elif not bn_ids and product_id and batch_name:
516
error_list.append(_('Expiry date is not set, so batch not selected.'))
518
error_list.append(_('Expiry date is not set.'))
521
batch_number = bn_ids[0]
518
523
return {'prodlot_id': batch_number, 'expired_date': expiry_date, 'error_list': error_list, 'warning_list': warning_list}