~unifield-team/unifield-wm/us-727

« back to all changes in this revision

Viewing changes to msf_doc_import/check_line.py

  • Committer: Quentin THEURET
  • Date: 2015-11-10 09:13:05 UTC
  • mto: This revision was merged to the branch mainline in revision 2670.
  • Revision ID: qt@tempo-consulting.fr-20151110091305-3uz0q7zecb7un906
US-670 [IMP] Rework the import of batch and expiry date on stock.picking

Show diffs side-by-side

added added

removed removed

Lines of Context:
474
474
    bn_cell_nb = kwargs['bn_cell_nb']
475
475
    ed_cell_nb = kwargs['ed_cell_nb']
476
476
    bn_obj = kwargs['bn_obj']
 
477
    product_obj = kwargs['product_obj']
477
478
    product_id = kwargs['product_id']
478
479
    date_format = kwargs['date_format']
479
480
    error_list = kwargs['to_write']['error_list']
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
492
493
 
 
494
    prd_brw = product_id and product_obj and product_obj.browse(cr, uid, product_id) or False
 
495
 
 
496
    bn_mgmt = prd_brw and prd_brw.batch_management
 
497
    ed_mgmt = prd_brw and prd_brw.perishable
 
498
 
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'))])
495
 
        if bn_ids:
496
 
            batch_number = bn_ids[0]
497
 
 
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)])
500
 
        if bn_ids:
501
 
            batch_number = bn_ids[0]
502
 
 
503
 
        # Set an error message for non matching between BN and Expiry date
504
 
        if 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))
506
 
 
507
 
        # Set expiry date with the life date of the BN
508
 
        expiry_date = bn_obj.browse(cr, uid, batch_number).life_date
509
 
 
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'))])
512
 
        if bn_ids:
513
 
            batch_number = bn_ids[0]
514
 
 
515
 
    if (batch_name or expiry_date) and not bn_ids:
516
 
        error_list.append(_('The Batch number was not found.'))
 
501
        if not bn_ids:
 
502
            if bn_obj.search(cr, uid, [('product_id', '=', product_id), ('name', '=', batch_name)]):
 
503
                if bn_mgmt:
 
504
                    error_list.append(_('The expiry date doesn\'t match with the expiry date of the batch. Batch not selected'))
 
505
                else:
 
506
                    error_list.append(_('The expiry date doesn\'t match with the expiry date of the batch. Expiry date not selected'))
 
507
            else:
 
508
                error_list.append(_('Batch not found.'))
 
509
    elif not bn_ids and product_id and expiry_date:
 
510
        if bn_mgmt:
 
511
            error_list.append(_('The Batch number is not set.'))
 
512
        elif ed_mgmt:
 
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:
 
515
        if bn_mgmt:
 
516
            error_list.append(_('Expiry date is not set, so batch not selected.'))
 
517
        else:
 
518
            error_list.append(_('Expiry date is not set.'))
 
519
 
 
520
    if bn_ids:
 
521
        batch_number = bn_ids[0]
517
522
 
518
523
    return {'prodlot_id': batch_number, 'expired_date': expiry_date, 'error_list': error_list, 'warning_list': warning_list}
519
524