170
147
'report_id': fields.many2one('expiry.quantity.report', string='Report', required=True),
171
148
'product_id': fields.many2one('product.product', string='Product', required=True),
172
'product_code': fields.related('product_id', 'default_code', string='Ref.', type='char'),
149
'product_code': fields.related('product_id', 'default_code', string='Reference', type='char'),
173
150
'product_name': fields.related('product_id', 'name', string='Name', type='char'),
174
151
'uom_id': fields.related('product_id', 'uom_id', string='UoM', type='many2one', relation='product.uom'),
175
'real_stock': fields.float(digits=(16, 2), string='Real stock'),
176
'expired_qty': fields.float(digits=(16, 2), string='Batch exp.'),
177
#'batch_number': fields.many2one('production.lot', string='Batch'),
178
'batch_number': fields.char(size=64, string='Batch'),
179
'expiry_date': fields.date(string='Exp. date'),
180
'location_id': fields.many2one('stock.location', string='Loc.'),
152
'real_stock': fields.float(digits=(16, 2), string='Total product real stock in location'),
153
'expired_qty': fields.float(digits=(16, 2), string='Batch expired quantity in location'),
154
'batch_number': fields.many2one('production.lot', string='Batch number'),
155
'expiry_date': fields.date(string='Expiry date'),
156
'location_id': fields.many2one('stock.location', string='Location'),
183
159
expiry_quantity_report_line()
601
561
_name = 'product.product'
602
562
_inherit = 'product.product'
604
def get_expiry_qty(self, cr, uid, product_id, location_id, monthly_consumption, d_values=None, context=None):
564
def get_expiry_qty(self, cr, uid, product_id, location_id, monthly_consumption, context={}):
606
566
Get the expired quantity of product
568
move_obj = self.pool.get('stock.move')
569
uom_obj = self.pool.get('product.uom')
570
product_obj = self.pool.get('product.product')
571
lot_obj = self.pool.get('stock.production.lot')
572
stock_obj = self.pool.get('stock.location')
614
monthly_consumption = 'rac'
574
monthly_consumption = 0.00
616
576
# Get the monthly consumption
617
if d_values.get('reviewed_consumption', False):
618
monthly_consumption = 'fmc'
619
elif d_values.get('past_consumption', False):
620
monthly_consumption = 'amc'
577
if context.get('reviewed_consumption', False):
578
monthly_consumption = product_obj.browse(cr, uid, product_id, context=context).reviewed_consumption
579
elif context.get('monthly_consumption', False):
580
monthly_consumption = product_obj.browse(cr, uid, product_id, context=context).monthly_consumption
622
monthly_consumption = d_values.get('manual_consumption', 0.00)
623
context.update({'manual_consumption': monthly_consumption})
625
product = self.browse(cr, uid, product_id, context=context)
626
# Get the delivery lead time of the product if the leadtime is not defined in rule and no supplier found in product form
627
delivery_leadtime = product.procure_delay and round(int(product.procure_delay)/30.0, 2) or 1
628
# Get the leadtime of the rule if defined
629
if 'leadtime' in d_values and d_values.get('leadtime', 0.00) != 0.00:
630
delivery_leadtime = d_values.get('leadtime')
631
elif product.seller_ids:
632
# Get the supplier lead time if supplier is defined
633
# The seller delay is defined in days, so divide it by 30.0 to have a LT in months
634
delivery_leadtime = product.seller_delay and round(int(product.seller_delay)/30.0, 2) or 1
636
delta = (delivery_leadtime + d_values.get('coverage', 0.00))*30.0
638
report_data = {'date_from': today().strftime('%Y-%m-%d'),
639
'date_to': (today() + RelativeDateTime(days=delta)).strftime('%Y-%m-%d'),
640
'consumption_type': monthly_consumption,
641
'consumption_from': d_values.get('consumption_period_from'),
642
'consumption_to': d_values.get('consumption_period_to'),
643
'location_id': location_id}
645
report_obj = self.pool.get('product.likely.expire.report')
646
line_obj = self.pool.get('product.likely.expire.report.line')
648
exp_context = context.copy()
649
exp_context.update({'only_product_ids': [product_id]})
650
report_id = report_obj.create(cr, uid, report_data, context=exp_context)
652
report_obj.process_lines(cr, uid, report_id, context=exp_context)
654
lines = line_obj.search(cr, uid, [('report_id', '=', report_id)], context=context)
655
for line in line_obj.browse(cr, uid, lines, context=context):
656
if line.product_id.id == product_id:
657
return line.total_expired
660
# location_ids = stock_obj.search(cr, uid, [('location_id', 'child_of', location_id)])
662
# move_ids = move_obj.search(cr, uid, ['|', ('location_id', 'in', location_ids), ('location_dest_id', 'in', location_ids),
663
# ('product_id', '=', product_id), ('prodlot_id', '!=', False)], context=context)
666
# for move in move_obj.browse(cr, uid, move_ids, context=context):
667
# if not move.prodlot_id.id in lots:
668
# lots.append(move.prodlot_id.id)
670
# # Get all lots for the product product_id
671
# lot_ids = lot_obj.search(cr, uid, [('product_id', '=', product_id), ('stock_available', '>', 0.00), ('id', 'in', lots)], \
672
# order='life_date', context=context)
676
# # Sum of months before expiry
682
# for lot in lot_obj.browse(cr, uid, lot_ids, context=context):
683
# life_date = strptime(lot.life_date, '%Y-%m-%d')
684
# rel_time = RelativeDateDiff(life_date, now())
685
# ni = round((rel_time.months*30 + rel_time.days)/30.0, 2)
686
# if last_qty == False:
687
# last_qty = uom_obj._compute_qty(cr, uid, lot.product_id.uom_id.id, (ni-sum_ni)*monthly_consumption, lot.product_id.uom_id.id)
688
# if last_date > life_date:
689
# expired_qty = lot.stock_available
690
# elif ni - sum_ni > 0.00:
691
# expired_qty += last_qty
692
# last_qty = uom_obj._compute_qty(cr, uid, lot.product_id.uom_id.id, (ni-sum_ni)*monthly_consumption, lot.product_id.uom_id.id)
582
monthly_consumption = context.get('manual_consumption', 0.00)
584
location_ids = stock_obj.search(cr, uid, [('location_id', 'child_of', location_id)])
586
move_ids = move_obj.search(cr, uid, ['|', ('location_id', 'in', location_ids), ('location_dest_id', 'in', location_ids),
587
('product_id', '=', product_id), ('prodlot_id', '!=', False)], context=context)
590
for move in move_obj.browse(cr, uid, move_ids, context=context):
591
if not move.prodlot_id.id in lots:
592
lots.append(move.prodlot_id.id)
594
# Get all lots for the product product_id
595
lot_ids = lot_obj.search(cr, uid, [('product_id', '=', product_id), ('stock_available', '>', 0.00), ('id', 'in', lots)], \
596
order='life_date', context=context)
600
# Sum of months before expiry
606
for lot in lot_obj.browse(cr, uid, lot_ids, context=context):
607
life_date = strptime(lot.life_date, '%Y-%m-%d')
608
rel_time = RelativeDateDiff(life_date, now())
609
ni = round((rel_time.months*30 + rel_time.days)/30.0, 2)
610
if last_qty == False:
611
last_qty = uom_obj._compute_qty(cr, uid, lot.product_id.uom_id.id, (ni-sum_ni)*monthly_consumption, lot.product_id.uom_id.id)
612
if last_date > life_date:
613
expired_qty = lot.stock_available
614
elif ni - sum_ni > 0.00:
615
expired_qty += last_qty
616
last_qty = uom_obj._compute_qty(cr, uid, lot.product_id.uom_id.id, (ni-sum_ni)*monthly_consumption, lot.product_id.uom_id.id)
698
622
product_product()