'Generate stock move lots'

def _generate_lot_ids(self):

    self.ensure_one()
    MoveLot = self.env['stock.move.lots']
    tracked_moves = self.move_raw_ids.filtered((lambda move: ((move.state not in ('done', 'cancel')) and (move.product_id.tracking != 'none') and (move.product_id != self.production_id.product_id))))
    for move in tracked_moves:
        qty = (move.unit_factor * self.qty_producing)
        if (move.product_id.tracking == 'serial'):
            while (float_compare(qty, 0.0, precision_rounding=move.product_uom.rounding) > 0):
                MoveLot.create({'move_id': move.id, 'quantity': min(1, qty), 'quantity_done': min(1, qty), 'production_id': self.production_id.id, 'workorder_id': self.id, 'product_id': move.product_id.id, 'done_wo': False})
                qty -= 1
        else:
            MoveLot.create({'move_id': move.id, 'quantity': qty, 'quantity_done': qty, 'product_id': move.product_id.id, 'production_id': self.production_id.id, 'workorder_id': self.id, 'done_wo': False})
